Search code examples
ethereumsolidity

How I can initialize a struct with an empty address array in it?


pragma solidity >=0.4.22 <0.7.0;

contract Storage {

    struct Client {
        bool enrolled;
        bytes32 fullName;
        address[] reference;
    }

    Client newClient = Client(true, 0x7465737400000000000000000000000000000000000000000000000000000000, address[]);
}

This is the code, simplified. I know...the best solution is to change everything and replace array with a mapping. But I need to do thing in this way.

Any idea ?


Solution

  • Try this - the 0 in the braces means you're initializing a dynamic array of size 0.

    Client newClient = Client(true, 0x7465737400000000000000000000000000000000000000000000000000000000, new address[](0));