当尝试设置结构数组时,出现错误消息“未声明的标识符。您是指“候选”还是“候选”?”
我试图通过写来创建一个空数组
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");
}
}
答案 0 :(得分:0)
更改
mapping(uint => Candidate) candidate;
到
mapping(uint => Candidate) candidates;
和
function createCandidate(string storage name ) private
到
function createCandidate(string memory name ) private