`
//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. i couldnt solve it because the "value" variable is already identified it doesn neew to be memoried
CodePudding user response:
string is a reference type, so you need to specify its data location. In this case, the value is loaded from storage to memory, and then returned from the memory.
function get() public returns(string memory) {
return value;
}
