[Ethereum] constructor arguments require ‘memory’ as a data location but not uint

dapp-developmentremixsolidity

Ok I am trying to figure out why Remix IDE is throwing an error saying the

Data location 'memory' must be given…..

for a string argument but the uint arguments don't throw any error?

pragma solidity >=0.4.25 <0.6.0;

contract Monopoly {

string public player1;
uint32 public player2;
uint32 public player3;

    constructor(string memory _player1, uint32 _player2, uint32 _player3) public {
    player1 = _player1;
    player2 = _player2;
    player3 = _player3;
    }
}

Best Answer

Have a look here: https://solidity.readthedocs.io/en/latest/050-breaking-changes.html#explicitness-requirements

Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables. For example, change uint[] x = m_x to uint[] storage x = m_x, and function f(uint[][] x) to function f(uint[][] memory x) where memory is the data location and might be replaced by storage or calldata accordingly. Note that external functions require parameters with a data location of calldata.

string is a specific type of array, so this logic applies.

This sort of issue, and the possibility such things might pop up in the future is one reason I incline to specific versions in pragma instead of ranges. That way if you switched compilers (possibly without being aware of it) you wouldn't get new and weird issues - just a complaint about the compiler version.

Hope it helps.