小编Chr*_*ang的帖子

如何在结构中初始化空数组[Solidity]

当创建结构时,我很难为结构初始化一个空数组。

pragma solidity ^0.5.1;

contract Board {

    //storage
    Post[] posts;

    //struct
    struct Post {
        address author;
        string title;
        string content;
        Comment[] comments;
    }

    struct Comment {
        address author;
        string comment;
    }

    //add-post
    function addPost(address _author, string memory _title, string memory _content) public {
        posts.push(Post(_author, _title, _content, /* HERE IS THE PROBLEM POINT */));
    }
}
Run Code Online (Sandbox Code Playgroud)

我想用空数组(类型:注释)初始化注释(结构成员)。我应该使用哪个代码来解决问题点?

郎:坚固

谢谢。

blockchain ethereum solidity

5
推荐指数
1
解决办法
3232
查看次数

标签 统计

blockchain ×1

ethereum ×1

solidity ×1