0

I am not sure how to return a struct that is inside an array of structs. This is my code:

contract StudentsInfoTracker{

    Student[] students;

    struct Student{
        string name;
        address ethAddress;
        uint numberInClass;
        uint[] marks;
    }
    function getStudent(uint) public view returns(string memory name, address ethAddress, uint numberInClass, uint[] memory marks){
        return(students[uint].name, students[uint].ethAddress, students[uint].numberInClass, students[uint].marks);
    }

I need to return the student given the uint index. I know I can't return a complete struct but I can try to retrieve its data. Anyway I get this error:

TypeError: Type type(uint256) is not implicitly convertible to expected type uint256.

2

You forgot to name your variable. You only gave it a type. Try this:

function getStudent(uint id) ... {
    return (students[id].name, students[id].ethAddress, ...);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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