0
//SPDX-License-Identifier:MIT

pragma solidity 0.6.1;

contract ExampleMapping1{

    mapping(uint => string) names;

    struct Name{
        string yourName;
    }

    function MyNames(uint _rNo,string memory _yourName) public{
        names[_rNo] = Name[_yourName];
    }
}

1 Answer 1

0

Your code needs some work. You have to create an instance or mapping to access the struct object. You cannot access it directly. Try something like this:

//SPDX-License-Identifier:MIT
pragma solidity 0.6.1;

contract ExampleMapping1{
    struct Name{
        string yourName;
    }
    mapping(string => Name) public nameStruct;
    mapping(uint => string) names;

    function MyNames(uint _rNo,string memory _yourName) public{
        names[_rNo] = nameStruct[_yourName].yourName;
    }
}

Your Answer

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

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