Consider the case where I want to get the elements of a struct via a public mapping from product contract to price contract:
contract Product{
struct prod{
string name;
uint id;
bool status;
}
mapping(uint => prod) public products;
function updateStudent (string n, uint ID) {
products[ID].n = "Temp";
products[ID].status = true;
}
}
At this point, I would like to access the elements of the mapping from a different contract:
contract ProductList {
address productAddr;
string p_name;
uint p_id;
Product p;
function ProductList(address addr) {
productAddr = addr;
p = Product(addr);
}
function readProduct (uint u) returns (bool c) {
p_id = p.products[u].id;
p_name = p.products[u].name;
c = true;
}
}
In the above scenario, I am always getting the error: Indexed expression has to a type, mapping or array (is function...). Any suggestions would be greatly helpful!
mapping(uint => mapping(uint => ProductStruct) public productStructs;
How can I access the element of the ProductStruct from the outer contract? Thing likep.getproduct(u1)(u2)
doesn't work. – Roman Lashta Oct 18 '18 at 13:53