Lesson 2: TypeError: Data location must be "memory" or "calldata" for return parameter in function, but none was given. #2682
Answered
by
alymurtazamemon
Boluwatife-Aminu-Taiwo
asked this question in
Q&A
-
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "./Practice.sol";
contract Practice2{
Practice[] public practiceArray;
function createNewPracticeContract() public {
Practice practice2 = new Practice();
practiceArray.push(practice2);
}
function storeName(string memory _addressName, uint256 _practice2Index ) public {
practiceArray[_practice2Index].store(_addressName);
}
function nameGet(uint256 _practice2Index) public view returns(string){
return practiceArray[_practice2Index].retrieve();
} **// this is where the error is**
} |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Sep 18, 2022
Replies: 3 comments 7 replies
-
@devtiff - function nameGet(uint256 _practice2Index) public view returns(string){
+ function nameGet(uint256 _practice2Index) public view returns(string memory){ Add |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
alymurtazamemon
-
Incorporate Ali's fix which adds the If it persists, please post the terminal as well as the entire code--we will look into it! |
Beta Was this translation helpful? Give feedback.
0 replies
-
These are the codes Practice.solpragma solidity ^0.8.8;
contract Practice{
uint256 public num1;
uint256 public num2;
mapping (string => uint256) public nameToNumber;
mapping (string => bool) public nameToIsRegistered;
function store(uint256 _num1, uint256 _num2) public {
num1 = _num1;
num2 = _num2;
}
function multiply() public view returns(uint256){
return num1 * num2;
}
struct Info {
string name;
uint256 number;
bool isRegistered;
}
Info[] public walletInfo;
function addInfo(string memory _name, uint256 _number, bool _isRegistered) public {
walletInfo.push(Info(_name, _number, _isRegistered));
nameToNumber[_name] = _number;
nameToIsRegistered[_name] = _isRegistered;
}
} Practice2.solpragma solidity ^0.8.8;
import "./Practice.sol";
contract Practice2{
Practice[] public practiceArray;
function createNewPracticeContract() public {
Practice practice2 = new Practice();
practiceArray.push(practice2);
}
function storeName(string memory _addressName, uint256 _practice2Index ) public {
practiceArray[_practice2Index].store(_addressName);
}
function nameGet(uint256 _practice2Index) public view returns(string memory){
return practiceArray[_practice2Index].retrieve();
}
}
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@devtiff
Add
memory
keyword along with the string in returns