Skip to main content
deleted 311 characters in body
Source Link
user19510
  • 28.1k
  • 2
  • 32
  • 49

I think the compiler errors are fairly self-explanatory, but here's a fixed version:

pragma solidity ^0.5.0;

contract Courses {
    struct Instructor {
        uint age;
        string fName;
        string lName;
    }
    
    mapping (address => Instructor) instructors;
    address[] public instructorAccts;
    
    function setInstructor(address _address, uint _age, string memory _fName, string memory _lName) public {
        Instructor storage instructor = instructors[_address];
    
        instructor.age = _age;
        instructor.fName = _fName;
        instructor.lName = _lName;
    
        instructorAccts.push(_address);
    }
    
    function getInstructors() public view returns (address[] memory) {
        return instructorAccts;
    }
}
  • I gave a proper type to instructor.
  • I gave a data location for instructor, though it was really unclear to me whether that should be storage or memory. If storage, it's going to duplicate each instructor (change their details and then also push a new copy onto the end of the array). If memory, it's reading from instructors for no reason. Neither makes much sense to me. :-)
  • I gave the return value of getInstructors a data location.
  • I deleted the strange -1 that wasn't doing anything.

I think the compiler errors are fairly self-explanatory, but here's a fixed version:

pragma solidity ^0.5.0;

contract Courses {
    struct Instructor {
        uint age;
        string fName;
        string lName;
    }
    
    mapping (address => Instructor) instructors;
    address[] public instructorAccts;
    
    function setInstructor(address _address, uint _age, string memory _fName, string memory _lName) public {
        Instructor storage instructor = instructors[_address];
    
        instructor.age = _age;
        instructor.fName = _fName;
        instructor.lName = _lName;
    
        instructorAccts.push(_address);
    }
    
    function getInstructors() public view returns (address[] memory) {
        return instructorAccts;
    }
}
  • I gave a proper type to instructor.
  • I gave a data location for instructor, though it was really unclear to me whether that should be storage or memory. If storage, it's going to duplicate each instructor (change their details and then also push a new copy onto the end of the array). If memory, it's reading from instructors for no reason. Neither makes much sense to me. :-)
  • I gave the return value of getInstructors a data location.
  • I deleted the strange -1 that wasn't doing anything.

I think the compiler errors are fairly self-explanatory, but here's a fixed version:

pragma solidity ^0.5.0;

contract Courses {
    struct Instructor {
        uint age;
        string fName;
        string lName;
    }
    
    mapping (address => Instructor) instructors;
    address[] public instructorAccts;
    
    function setInstructor(address _address, uint _age, string memory _fName, string memory _lName) public {
        Instructor storage instructor = instructors[_address];
    
        instructor.age = _age;
        instructor.fName = _fName;
        instructor.lName = _lName;
    
        instructorAccts.push(_address);
    }
    
    function getInstructors() public view returns (address[] memory) {
        return instructorAccts;
    }
}
  • I gave a proper type to instructor.
  • I gave a data location for instructor.
  • I gave the return value of getInstructors a data location.
  • I deleted the strange -1 that wasn't doing anything.
Source Link
user19510
  • 28.1k
  • 2
  • 32
  • 49

I think the compiler errors are fairly self-explanatory, but here's a fixed version:

pragma solidity ^0.5.0;

contract Courses {
    struct Instructor {
        uint age;
        string fName;
        string lName;
    }
    
    mapping (address => Instructor) instructors;
    address[] public instructorAccts;
    
    function setInstructor(address _address, uint _age, string memory _fName, string memory _lName) public {
        Instructor storage instructor = instructors[_address];
    
        instructor.age = _age;
        instructor.fName = _fName;
        instructor.lName = _lName;
    
        instructorAccts.push(_address);
    }
    
    function getInstructors() public view returns (address[] memory) {
        return instructorAccts;
    }
}
  • I gave a proper type to instructor.
  • I gave a data location for instructor, though it was really unclear to me whether that should be storage or memory. If storage, it's going to duplicate each instructor (change their details and then also push a new copy onto the end of the array). If memory, it's reading from instructors for no reason. Neither makes much sense to me. :-)
  • I gave the return value of getInstructors a data location.
  • I deleted the strange -1 that wasn't doing anything.