【问题标题】:Solidity - Filling and using array of arraySolidity - 填充和使用数组数组
【发布时间】:2017-02-28 16:40:49
【问题描述】:

我与以下数据结构签订了合同:

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[] memory 类型复制到存储。

【问题讨论】:

    标签: solidity


    【解决方案1】:

    如果您尝试通过 web3 或类似的桥接器访问合同。

    bridge 仍然不支持数组数组,但solidity 支持!

    我猜如果错误是可靠的,你会看到不同类型的错误。

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      使用push() 方法而不是Solidity 分配。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多