汇总:tuple中使用'[]'标识一个对象,而不是'{}'.
合约示例
pragma solidity ^0.7.0;
pragma abicoder v2;
contract ZXL {
struct Man {
string name;
uint age;
}
Man[] persons;
constructor() public {
persons.push(Man("mame",11));
persons.push(Man("mame1",22));
}
// ["aa",1]
function addMan(Man memory man) public{
persons.push(man);
}
// [["aa",1],["a2",2]]
function addMen(Man[] memory men) public{
for(uint i=0;i<men.length;i++){
persons.push(men[i]);
}
}
function getMen() view public returns(Man[] memory){
return persons;
}
}
网友评论