I am failing to use the push method against a dynamic array declared as a state variable. How can I do this?
I declare a dynamic array of addresses as a state variable like below:
contract Sample {
address[] public path;
}
Then, inside a function of this contract, I push two addresses into the dynamic array:
path.push(address1, address2);
And I get this compile error:
CompileError: Sample.sol:91:9: TypeError: Member "push" not found or not visible after argument-dependent lookup in address[] storage ref.
path.push(address1, address2);
^-------^
Best Answer
You can only push one item at a time. In your case, simply split up your function: