在结构 CV.experience 存储引用中进行参数相关查找后,成员 "push" 未找到或不可见
Member "push" not found or not visible after argument-dependent lookup in struct CV.experience storage ref
希望你一切顺利!实际上,我正在尝试创建一个包含结构图的智能合约 我想将新体验存储在一个映射中,其中键是我在函数参数中获得的地址,但不幸的是,我没有出现此错误时知道问题所在:
来自 solidity:TypeError:在结构 CV.experience 存储引用中进行参数相关查找后,未找到成员“push”或不可见。 --> contracts/experience.sol:19:9:
经验[_addressCompagnie].push(
密码是:
pragma solidity >=0.7.0 <0.9.0;
contract CV {
struct experience {
address addressCompagnie;
string nomCompagnie;
string titrePoste;
string description;
bool valide;
}
mapping(address => experience ) experiences ;
function addExperience(
address _addressCompagnie,
string memory _nomCompagnie,
string memory _titrePoste,
string memory _description
) public {
experiences[_addressCompagnie].push(
experience(
_addressCompagnie,
_nomCompagnie,
_titrePoste,
_description,
false
)
);
}
}'''
thanks for helping me !
映射值的类型是experience
,不是experience[]
(一个数组),所以你不能push()
进入它。
根据您的用例,您可以在不推送的情况下分配单个值
mapping(address => experience) experiences;
function addExperience(...) public {
// set the single value
experiences[_addressCompagnie] = experience(...);
}
或将映射定义更改为experience[]
(experience
的数组)然后推入其中。
mapping(address => experience[]) experiences;
function addExperience(...) public {
// push into the array
experiences[_addressCompagnie].push(experience(...));
}
希望你一切顺利!实际上,我正在尝试创建一个包含结构图的智能合约 我想将新体验存储在一个映射中,其中键是我在函数参数中获得的地址,但不幸的是,我没有出现此错误时知道问题所在:
来自 solidity:TypeError:在结构 CV.experience 存储引用中进行参数相关查找后,未找到成员“push”或不可见。 --> contracts/experience.sol:19:9: 经验[_addressCompagnie].push(
密码是:
pragma solidity >=0.7.0 <0.9.0;
contract CV {
struct experience {
address addressCompagnie;
string nomCompagnie;
string titrePoste;
string description;
bool valide;
}
mapping(address => experience ) experiences ;
function addExperience(
address _addressCompagnie,
string memory _nomCompagnie,
string memory _titrePoste,
string memory _description
) public {
experiences[_addressCompagnie].push(
experience(
_addressCompagnie,
_nomCompagnie,
_titrePoste,
_description,
false
)
);
}
}'''
thanks for helping me !
映射值的类型是experience
,不是experience[]
(一个数组),所以你不能push()
进入它。
根据您的用例,您可以在不推送的情况下分配单个值
mapping(address => experience) experiences;
function addExperience(...) public {
// set the single value
experiences[_addressCompagnie] = experience(...);
}
或将映射定义更改为experience[]
(experience
的数组)然后推入其中。
mapping(address => experience[]) experiences;
function addExperience(...) public {
// push into the array
experiences[_addressCompagnie].push(experience(...));
}