Solidity with error TypeError: Member not found or not visible

1

This is my current code:

pragma solidity ^0.4.18;

contract Voting {
  struct Voter {
    bool voted;
    address delegate;
    bytes32 name;
    uint weight;
    uint vote;

  }

  mapping (bytes32 => uint8) public votesReceived;
  uint[100] public people;
  uint32 public counter;
  bytes32[] public candidateList;

  constructor(bytes32[] candidateNames) public {
    candidateList = candidateNames;
    people[1] = 12;
    counter = 1;

  }

  function totalVotesFor(bytes32 candidate) view public returns (uint8) {
    require(validCandidate(candidate));
    return votesReceived[candidate];
  }

  function voteForCandidate(bytes32 candidate) view public {
    require(validCandidate(candidate));
    votesReceived[candidate];
  }

  function validCandidate(bytes32 candidate) view public returns (bool) {
    for(uint i = 0; i <


 candidateList.length; i++) {
    if (candidateList[i] == candidate) {
    return true;
    }
    }
    return false;
  }

  address public chairperson;
  mapping(address => Voter) public voters;

  function validation(bytes32[] candidateNames) internal {
    chairperson = msg.sender;
    voters[chairperson].weight = 1;
  }

  function giveRightToVote(address voter) {
  require ((msg.sender == chairperson) && !voters[voter].voted);
  voters[voter].weight = 1;
  }

  function delegate(address to) public {
    Voter sender = voters[msg.sender];
    require(!sender.voted);
    require(to != msg.sender);

  while(voters[to].delegate != address(0)) {
    to = voters[to].delegate;
    require(to != msg.sender);
    }

    sender.voted = true;
    sender.delegate = to;
    Voter delegate = voters[to];

  if (delegate.voted) {
  candidateList[delegate.vote].voteForCandidates += sender.weight;
    } else {
    delegate.weight += sender.weight;
    }
  }

  function vote(uint proposal) {
    Voter sender = voters[msg.sender];
    require(!sender.voted);
    sender.voted = true;
    sender.vote = proposal;
  }
  }

And the error it throws is:

  

/ * TypeError: Member "voteForCandidates" not found or not visible   after argument-dependent lookup in bytes32   candidateList [delegate.vote] .voteForCandidates + = sender.weight; * /

^ -------------------------------------------- ^

    
asked by Jusselly Sarai Moreno Castrove 21.05.2018 в 18:02
source

1 answer

0

It is that the data type of the candidateList property is bytes32 and does not have the voteForCandidates property, so you get the error: 'TypeError: Member "voteForCandidates" not found or not visible "

    
answered by 14.06.2018 в 20:19