[英]Solidity Js, on function get i get an error as "TypeError: Data location must be "memory" or "calldata" for return parameter in function
` `
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyContract{
string value;
constructor() public {
value = "MyValue";
}
function get() public returns(string) {
return value;
}
function set(string memory _value) public {
value = _value;
}
}`
on function get i get an error as TypeError: Data location must be "memory" or "calldata" for return parameter in function, but none was given.在函数 get 我得到一个错误,因为 TypeError: Data location must be "memory" or "calldata" for return parameter in function,但没有给出。 i couldnt solve it because the "value" variable is already identified it doesn neew to be memoried
我无法解决它,因为“值”变量已经被识别,它不需要被记忆
string
is a reference type, so you need to specify its data location . string
是引用类型,所以需要指定它的数据位置。 In this case, the value is loaded from storage to memory, and then returned from the memory
.在这种情况下,值从存储加载到内存,然后从
memory
中返回。
function get() public returns(string memory) {
return value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.