Reputation: 161
I tried to compile my code, but I got the following error:
TypeError: Data location must be "memory" for parameter in function, but none was given
my code:
pragma solidity ^0.5.0;
contract memeRegistry {
string url;
string name;
uint timestamp;
function setmeme(string _url,string _name, uint _timestamp) public{
url = _url;
name = _name;
timestamp = _timestamp;
}
}
Upvotes: 16
Views: 15656
Reputation: 11
You need to make the return parameters explicitly memory:
Thus,
function setmeme(string _url,string _name, uint _timestamp) public
Becomes
function setmeme(string memory _url, string memory _name, uint _timestamp) public{
Upvotes: 0
Reputation: 390
//The version I have used is 0.5.2
pragma solidity ^0.5.2;
contract Inbox{
string public message;
//**Constructor** must be defined using “constructor” keyword
//**In version 0.5.0 or above** it is **mandatory to use “memory” keyword** so as to
//**explicitly mention the data location**
//you are free to remove the keyword and try for yourself
constructor (string memory initialMessage) public{
message=initialMessage;
}
function setMessage(string memory newMessage)public{
message=newMessage;
}
function getMessage()public view returns(string memory){
return message;
}
}
Upvotes: 5
Reputation: 3950
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.
Add memory
after string
function setmeme(string memory _url, string memory _name, uint _timestamp) public{
check here for Solidity 0.5.0. changes https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html
Upvotes: 27
Reputation: 1085
Select a different version of the solidity compiler. ^0.4.25
works for me.
The version of the solidity compiler has to be set both on the file and in the compile tab on remix(it is a drop-down menu).
Upvotes: 1