你能告诉我为什么我会在坚固性上获取此错误消息
从坚固性:
DeclarationError: Identifier already declared.
--> contracts/MySimpleStorage.sol:16:5:
|
16 | people[] public people;
|
Note: The previous declaration is here:
--> contracts/MySimpleStorage.sol:11:5:
|
11 | struct people {
| (Relevant source part starts here and spans across multiple lines).
错误2
来自坚固性:
TypeError: Expected callable expression before call options.
contracts/MySimpleStorage.sol:32:21:
|
32 | people.push(people{favoriteNumber: _favoriteNumber, name: _name});
这是主要代码
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract MySimpleStorage {
//this will get initilized to 0 since we did not state the number
uint256 public favoriteNumber;
bool favoriteBool;
struct people{
uint256 favoriteNumber;
string name;
}
People[] public people;
mapping(string => uint256) public nameToFavoriteNumber;
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber;
}
function retrieve() public view returns(uint256) {
return favoriteNumber;
}
function addPerson(string memory _name, uint256 _favoriteNumber) public{
people.push(people(_favoriteNumber, _name));
nameToFavoriteNumber[_name] = _favoriteNumber;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题来自案例敏感性。您已经在此处声明了结构较低的结构
您需要在此之前的动态阵列之前声明相同[]
小写是您的对象名称出现在公共按钮上,这可能是公开的人
bottonname.push(structname ...
This issue is from case sensitivity. you have declared struct with lower case here -struct people
You will need to declare same before the dynamic array here-People[]
Lowercase here is your object name that appears on the button in public, and this could be anything -public people
Bottonname.push(structNAME...
由于以下错误的错误:
struct people {
people []公共人员;
上述
> People
已经在结构中声明,您再次将People
称为数组名称。相反,应该是:
因为以坚固的方式,结构名称通常按照普通命名约定为大写。
因此,
人
被声明为类型People []
的公共数组。从坚固性:
TypeError:通话选项之前的预期可呼叫表达式
,是由于以下语句中缺少括号:
people.push(people {fairiteNumber:_favoriteNumber,name:_name});
而不是:应该是:
people.push(
people(
{fairiteNumber:_favoriteNumber,name:_name}
)
);
我希望这会有所帮助!
You are facing errors because of few the below-mentioned errors:
struct people{
People[] public people;
The aforementioned
people
is already declared in a struct, and you are again declaringpeople
as an array name.Instead, it should be:
because in Solidity, struct names are typically capitalized as per the common naming conventions.
So
people
is declared as a public array of typePeople[]
.from solidity:
TypeError: Expected callable expression before call options
It is due to a missing bracket in the below statement:
people.push(people{favoriteNumber: _favoriteNumber, name: _name});
Instead, it should be:
people.push(
people(
{favoriteNumber: _favoriteNumber, name: _name}
)
);
I hope this helps!