2

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); ^-------^ 
1
  • 2
    I admit that this error-message is indeed confusing, and that it doesn't imply to the problem in your code. Nevertheless, you should push each address separately, as push does not support multiple values at once. Commented Nov 5, 2020 at 12:27

1 Answer 1

1

You can only push one item at a time. In your case, simply split up your function:

path.push(address1); path.push(address2); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.