7

solidity的struct中包含了mapping,在使用中报内存初始化错误

 2 years ago
source link: https://learnblockchain.cn/question/2896
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

solidity的struct中包含了mapping,在使用中报内存初始化错误 | 登链社区 | 技术问答

solidity的struct中包含了mapping,在使用中报内存初始化错误

错误提示:struct contraining a (nested) mapping cannot be constructed

请教该怎么处理?

找了一下文档:https://docs.soliditylang.org/en/v0.7.1/070-breaking-changes.html#mappings-outside-storage
文档的意思是0.7版本后优化了这些不安全的写法,解决办法难道只有把mapping从struct中独立出来吗???

image.png

image.png

Tiny熊 - 布道者 2天前

  擅长:智能合约,以太坊

换一个写法:

Proposal storage newProposal = proposals[proposalCount];
newProposal.id = proposalCount;
newProposal.proposer = msg.sender;
newProposal.eta = 0;
...
您需要登录后才可以回答问题,登录 或者 注册

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK