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 bestorage
ormemory
. Ifstorage
, it's going to duplicate each instructor (change their details and then also push a new copy onto the end of the array). Ifmemory
, it's reading frominstructors
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.