成员“推”在参数依赖性查找之后找不到或看不到
问题
此行似乎存在一些问题family.people.push(people [x]);
我一直在ement
ement'push'''supl''disper'找不到或在参数依赖性依赖性查找之后< /代码>当我尝试与布朗尼编译时。
我尝试了什么
我看到了一些帖子,但与类似的帖子有关。我确实试图将传入的数组投射到其类型上,但这只是导致了更多例外。
代码
pragma solidity ^0.8.9;
contract Person{
string public FirstName;
string public LastName;
}
contract Family{
Person[] public People;
}
contract FamilyManager{
Family[] Families;
function AddFamily(Person[] memory people) public {
Family family = new Family();
for(uint x; x < people.length; x++){
family.People.push(people[x]);
}
Families.push(family);
}
function GetFamilies() public view returns (Family[] memory){
return Families;
}
}
任何人都可以在这里发现我在做错什么还是链接到可以带来答案的文章?
Issue
There seems to be some issue with this line here family.People.push(people[x]);
I keep getting Member "push" not found or not visible after argument-dependent lookup
when I try to compile with brownie.
What have I tried
I saw a few SO posts with similar exceptions but it was related to type casting. I did try to cast my incoming array to its type but it just resulted in more exceptions.
Code
pragma solidity ^0.8.9;
contract Person{
string public FirstName;
string public LastName;
}
contract Family{
Person[] public People;
}
contract FamilyManager{
Family[] Families;
function AddFamily(Person[] memory people) public {
Family family = new Family();
for(uint x; x < people.length; x++){
family.People.push(people[x]);
}
Families.push(family);
}
function GetFamilies() public view returns (Family[] memory){
return Families;
}
}
Can anyone spot what I'm doing wrong here or link to an article that can lead to an answer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与
访问修饰符
有关。使用public
用于您的数组的修饰符仅生成getter
函数,而不是setter
。结果,您不能直接从另一个合同中推到一个数组。我创建了一个
public
函数,将元素添加到数组中,如下所示:I think it is related to
access modifiers
. Using thepublic
modifier for your array only generates thegetter
function for it and not thesetter
.As a result, you cannot directly push to an array from another contract. I created a
public
function to add elements to the array as follows: