1

I am trying to execute the following example listed in the documentation using solidity 0.4

pragma solidity ^0.4.0;
contract C {
    uint[] data1;
    uint[] data2;

    function appendOne() {
        append(data1);
    }

    function appendTwo() {
        append(data2);
    }

    function append(uint[] storage d) {
        d.push(1);
    }
}

But I get the error:

Error: Location has to be memory for publicly visible functions (remove the "storage" keyword).

When I remove the storage keyword I get another error:

Error: Member "push" is not available in uint256[] memory outside of storage. d.push(1);

Any solution?

1 Answer 1

3

try to use internal or private modifier :

pragma solidity ^0.4.0;
contract C {
    uint[] data1;
    uint[] data2;

    function appendOne() {
        append(data1);
    }

    function appendTwo() {
        append(data2);
    }

    function append(uint[] storage d) internal{
        d.push(1);
    }
}
3
  • the function parameters are in the storage or in memory?
    – Sig Touri
    Commented Oct 23, 2016 at 13:21
  • **state variables are always in storage **local variables always reference storage **parameters (also return) of functions: memory
    – Badr Bellaj
    Commented Oct 23, 2016 at 16:18
  • Why does using internal help? Commented Jun 28, 2018 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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