7

I am trying to initialize this struct and I can't figure out how to pass in a dynamically sized empty array..

      uint8[] id;
  users[msg.sender] = User( true, msg.sender, _username, block.timestamp, block.number, 0, id, 0);
17

The following will work:

contract Test {
    struct Object {
        uint a;
        string b;
        string[] c;
        mapping(uint => uint) d;
    }

    Object field;

    function Test() {
        field = Object({
            a: 1,
            b: "abc",
            c: new string[](0)
        });
    }
}
  • I get this error when I skip it: Error: Wrong argument count for function call: 7 arguments given but expected 8. – ethereal Jan 31 '17 at 0:54
  • My bad, it is mapping that you skip. I updated my answer. – Xavier Leprêtre B9lab Jan 31 '17 at 9:53
  • Ok great that works! – ethereal Jan 31 '17 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.