错误:“->”的基本操作数具有非指针类型

时间:2018-11-02 06:20:39

标签: c++ pointers

这是我的枚举头文件

//use like PostionType::President
enum PositionType
{ President,
VicePresident,
Secretary,
Treasurer,
Normal
};

在我的选票标题和cpp文件中

#include <list>
#include <iostream>
#include "Candidate.h"
#include "PositionType.h" //include enum

class BallotPaper
{
 private:
     PositionType _positionbp;
     std::list<Candidate> _candidatesbp;
 public:
     BallotPaper();         

    void setPositionBP(PositionType positionbp);
    PositionType getPositionBP();

    void setCandidateBP(std::list<Candidate> candidatesbp);
    std::list<Candidate> getCandidateBP();

    Candidate getCandidate(int index);
    void ShowCandidates();   
    ~BallotPaper();
   };

#include "BallotPaper.h"
#include <string>
#include <iostream>

void BallotPaper::setPositionBP(PositionType positionbp)
{
    _positionbp = positionbp;
}
PositionType BallotPaper::getPositionBP()
 {
    return _positionbp;
  }

 void BallotPaper::setCandidateBP(std::list<Candidate> candidatesbp)
 {
     _candidatesbp = candidatesbp;
 }
std::list<Candidate> BallotPaper::getCandidateBP()
{
    return _candidatesbp;
}

void BallotPaper::ShowCandidates()
{

    for(Candidate c : _candidatesbp)
    {
        c->IncreaseVoteCount();   //ERROR!!!!
    }
}

这将是我的候选标头和cpp文件

class Candidate:public Member
{
 private:
   int _votecount;
   PositionType _position;
 public:
   Candidate(std::string name, int id, std::string course, int contact,          std::string joindate, PositionType currentposition) ;
   ~Candidate();

void setVoteCount(int votecount);
int getVoteCount();

void setPosition(PositionType position);
PositionType getPosition();

void IncreaseVoteCount(); //increase _votecount
}; 

#include "Candidate.h"

Candidate::Candidate()
{
  _votecount = 0;
}

void Candidate::setVoteCount(int votecount)
{
  _votecount = votecount;
}
int Candidate::getVoteCount()
{
  return _votecount;
}

void Candidate::setPosition(PositionType position)
{
   _position = position;
}

PositionType Candidate::getPosition()
{
    return _position;
}


void Candidate::IncreaseVoteCount()
{
   _votecount++;
}

我知道这是一个超长的代码,感谢您耐心阅读。我的错误是,它似乎无法识别“候选c”中的“ IncreaseVoteCount”功能。

我试图多次仔细检查语法和代码,但我仍然不明白这里的错误是什么。

0 个答案:

没有答案