pragma solidity >= 0.4.25 < 0.6;
contract Bank {
struct Customer {
uint age;
}
Customer[][] customers;
function foo() public {
if (customers.length > 0) {
Customer[] storage northBranch = customers[0];
if (northBranch.length > 1) {
Customer storage customer = northBranch[1];
customer.age = 23;
}
} else {
Customer memory bob;
bob.age = 34;
customers.length += 1;
customers[0].push(bob);
}
}
}
I´m looking for examples of function that return and a array when a function is called. There are many examples but I couldent find a function that return an array with arrays inside with struct inside.
I try this but it doesnt work.
function get() external view returns (Customer[][]) {
/*Customer[][] memory resCustomer;
for(uint i = 0; i<customers.length;i++) {
resCustomer[i][] = customers[i][];
}*/
return (customers);
}
ERROR:
TypeError: This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
Any idea about how can I travel across the main array to get a inside array and the struct that is inside?
returns (Customers[][])
, notreturns (customers[][])
. Second, I bet that you can simply return yourcustomers
table, instead of replicating it first (i.e., inside the function, simply doreturn customers;
).