美文网首页
Remix中tuple传参

Remix中tuple传参

作者: 95加不满 | 来源:发表于2021-10-22 15:09 被阅读0次

汇总: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;
    }
    
}

调用测试

image.png

相关文章

网友评论

      本文标题:Remix中tuple传参

      本文链接:https://www.haomeiwen.com/subject/jzacaltx.html