0

Example code is shown below. I am just starting out and have seen examples in the declaration of the specific types instead however I don't know how to do this in the context of a struct.

contract Courses is Owned {

    struct Instructor {
        uint age;
        string fName;
        string sName;
    }

    mapping (address => Instructor) instructors;
    address[] public instructorAccts;

    function setInstructor(address _address, uint _age, string _fName, string _sName) onlyOwner public {

        var instructor = instructors[_address];

        instructor.age = _age;
        instructor.fName = _fName;
        instructor.sName = _sName;

        instructorAccts.push(_address) -1;
    }
}

2 Answers 2

2

Instructor storage instructor = instructors[_address];

hope it helps.

0
2

As the mapping declaration indicates, instructors maps to the Instructor type.

Instructor storage instructor = instructors[_address];
1
  • Thanks, yes I got confused by the syntax in the tutorial I'm following.
    – Ben Hook
    Jul 5, 2018 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.