数组返回“未声明的标识符。您是指“候选”还是“候选”?”

时间:2019-02-03 01:16:59

标签: solidity

当尝试设置结构数组时,出现错误消息“未声明的标识符。您是指“候选”还是“候选”?”

我试图通过写来创建一个空数组

uint[] memory candidate;

bytes[] memory candidate        

以上功能中我遇到了错误以将其实例化。但是,这也不起作用,并且会出错。它不会编译。

pragma solidity 0.5.0;

contract Election {
    string public candidate;

    struct Candidate {
        uint id;
        string name;
        uint voteCount;
    }

    mapping(uint => Candidate) candidate;

    uint public candidatesCount;

    function createCandidate(string storage name ) private {
        candidatesCount ++;
        candidates[candidatesCount] = Candidate(candidatesCount, name, 0);
    }  

    function addCandidates () public {
        createCandidate("Candidate1");
        createCandidate("Candidate2");
    }
}

1 个答案:

答案 0 :(得分:0)

更改

    mapping(uint => Candidate) candidate;

   mapping(uint => Candidate) candidates;

    function createCandidate(string storage name ) private

    function createCandidate(string memory name ) private