TypeError:函数中参数的数据位置必须为“内存”,但未指定任何位置

时间:2018-11-24 17:46:38

标签: solidity

pragma solidity ^ 0.5.0;

合同memeRegistry {

string url;
string name;
uint timestamp;

function setmeme(string _url,string _name, uint _timestamp) public{
    url = _url;
    name = _name;
    timestamp = _timestamp;

}   

}

4 个答案:

答案 0 :(得分:6)

结构,数组或映射类型的所有变量的显式数据位置现在是必需的。这也适用于函数参数和返回变量。

memory之后添加string

function setmeme(string memory _url, string memory _name, uint _timestamp) public{

在此处检查“固体” 0.5.0。更改https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html

答案 1 :(得分:3)

//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;
 }
}

答案 2 :(得分:0)

选择其他版本的Solidity编译器。 ^0.4.25为我工作。

必须在文件和remix的“编译”选项卡(这是一个下拉菜单)中都设置solidity编译器的版本。

答案 3 :(得分:0)

对我有用。

  • 字符串内存

enter image description here