Reputation: 45
mapping(uint => Info) private infos;
struct Info {
uint _id;
address _add;
}
function getInfo(uint _infoid) external view returns (uint, address) {
return infos[_infoid]; //to return id & add
}
I have another function that is creating the mapping using the struct so that's not an issue here.
The error I am facing is in getInfo()
from solidity:
TypeError: Different number of arguments in return statement than in returns declaration.
--> Contract.sol:97:9:
|
97 | return infos[_infoid];
Upvotes: 0
Views: 57
Reputation: 1387
If you write this return infos[_infoid];
you're returning only the object and not its attributes with relative values.
For fix this issue, you must access to the attributes inside the object in this case _id, _add using the statement:
[StructObject].[Attribute];
You can change your getInfo() method implementation with this:
function getInfo(uint _infoid) external view returns (uint, address) {
return (infos[_infoid]._id, infos[_infoid]._add);
}
Upvotes: 1