I am still learning the best way to use mappings and how to access mapped elements. I understand how they work, but I tried to write some simple code to map an ID to a name. It works fine except for the most important part, returning the name. Here is the code:
pragma solidity ^0.4.18;
contract A {
string public name;
function A(string _name) public {
name = _name;
}
function getName() public view returns (string) {
return name;
}
}
contract handleArray {
uint public arrIndex;
mapping(uint => address) testArray;
function handleArray() public {
arrIndex = 0;
}
function newEntry(address _newA) public {
testArray[arrIndex] = A(_newA);
arrIndex++;
}
function returnEntry(uint _index) public returns (string) {
return A(testArray[_index]).getName();
}
}
So if I leave out returnEntry, I can run everything. I can map new A's to an incremented ID. However, returnEntry does not compile in Remix. I get the error
Return argument type inaccessible dynamic type is not implicitly convertible to expected type (type of first return variable (string memory).
I would appreciate any help. Thanks.