simple storage factory.sol shadowing problem #1025
-
When I write SimpleStorage public simpleStorage; the compiler shows that " this declaration shadows an existing declaration" and "identifier not found or not unique". what should i do to solve this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
@Shawon-Mandal It looks like you are creating another object of SimpleStorage with same name, but for better understanding copy paste your code and format it with back ticks. |
Beta Was this translation helpful? Give feedback.
-
contract simpleStorage{
uint256 favouriteNumber;
// people public persons=people({favouriteNumber:33,Name:"Frank"}); //here this curlyBrackets{} means that we are going to get the data from the below struct people.
mapping(string =>uint256) public nameToFavouriteNumber; //think of mapping as a sort of dictonary.where each key is assinged with a certain value and each key returning a certain value.
//here,in this mapping,string is the key of the mapping and the uint256 is the value assinged to the key.
struct People{ //Here we have created a new type of people.Its like a datatype.ex:uint,string.
uint256 favouriteNumber;
string Name;
}
People[] public people; //we've created a array with the same name as the struct data type.so that we can add more similar data inside the array related to the struct People.
//here,People=struct People.and people is the array variable.
// function assignNumber(uint256 _favouriteNumber ) public{ //we are assinging favourite number with the function called assign number.inside the function,the parameter is set to uint.
// favouriteNumber=_favouriteNumber;
// }
function retriveNumber() public view returns(uint256){
return favouriteNumber;
}
//call data,memory,storage...call data is a temporary variable that cant be modified,memory is a temporary variable that can be modified.storage is a permanant variable that can be modified.
// temporary means that its data only stays inside the function.
// struct,mapping and arrays need to be given memory or call data keywords for adding them as different function parameters.
function addPerson(string memory _name, uint256 _favouriteNumber) public{ //here,string needs to be given memeory keyword because,string is secretly an array.
people.push(People(_favouriteNumber,_name)); //here,we are adding the favourite number and name inside the people array variable and the capitalised People refers to the struct data structure.
nameToFavouriteNumber[_name]=_favouriteNumber;
}
}
contract StorageFactory{
SimpleStorage public simpleStorage;
function createSimpleStorageContract() public{
simpleStorage= new SimpleStorage(); //this new keyword says to solidity that we are going to create another contract called simpleStorage.
}
} here is the code,mentioned above. |
Beta Was this translation helpful? Give feedback.
-
@Shawon-Mandal Your contract name match the variable name. Change this contract name - contract simpleStorage
+ contract SimpleStorage |
Beta Was this translation helpful? Give feedback.
-
thank you soo much!!! |
Beta Was this translation helpful? Give feedback.
@Shawon-Mandal Your contract name match the variable name.
Change this contract name