我与以下数据结构签订了合同:
struct Answer
{
bytes32 name; // short name (up to 32 bytes)
uint voteCount; // number of accumulated votes
}
struct Question
{
bytes32 name; // short name (up to 32 bytes);
Answer[] answers;
}
Question[] public questions;
我怎样才能填充阵列?
以下行不起作用:
function addQuestion(bytes32 _name, bytes32[] _answers) onlyOwner { // perhabs it should be possible that others as the owner can add
Answer[] memory answersLocal = new Answer[](_answers.length);
//Question memory question = Question(_name);
for (uint i = 0; i < _answers.length; i++) {
answersLocal[i] = Answer({
name: _answers[i],
voteCount: 0
});
}
questions.push(Question({
name: _name,
answers: answersLocal
}));
}
我在这里得到错误:
将类型struct Roadshow.Answer memory []内存复制到尚不支持的存储。
如果你试图通过web3或像这样的桥梁访问合同。
桥仍然不支持数组阵列,但坚固支持!
我猜如果错误是稳固的,你会看到不同类型的错误。
希望这可以帮助。
使用push()
方法代替Solidity分配。