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?

jrbedard
  • 524
  • 1
  • 6
  • 15
Sig Touri
  • 1,090
  • 2
  • 14
  • 23

1 Answers1

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);
    }
}
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75