0

May someone explain me why exactly string variable must be memory from solidity v5.0 and what does tha mean?

Thanks for your help.

1

why exactly string variable must be memory

That's not true. It would be helpful to know what you are reading that gives that impression.

This compiles:

pragma solidity 0.5.1;

contract StringStorage {

    string[] public str;

    function push(string memory s) public {
        str.push(s);
    }

    function pop() public view returns(string memory s) {
        string storage _s = str[str.length-1]; // not memory
        s = _s;
    }
}

I suspect it depends on context. You can only set to memory in public and external function arguments, because storage pointers from outside the contract don't make a lot of sense.

This compiles:

function set(uint i, string storage s) internal {
    string storage updateString = str[i];
    updateString = s;
}

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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