What I'm trying to do here is to add Voter
to a vector
that belongs to RegLogBook
and, RegLogBook
is an object that is owned by my Election
class. I don't know what I'm doing wrong here, the Voter
object is not being added to the vector
. The relevant codes are below, I've removed all the unnecessary parts.
Election.h
class Election
{
public:
Election();
~Election();
RegLogBook getRegLogBook();
private:
RegLogBook* _regLogBook;
};
Election.cpp
Election::Election()
{
_regLogBook = new RegLogBook();
}
RegLogBook Election::getRegLogBook() {
return *_regLogBook;
}
RegLogBook.h
class RegLogBook
{
public:
RegLogBook();
~RegLogBook();
vector<Voter*> getVoterList();
private:
vector<Voter*> _voterList;
};
RegLogBook.cpp
vector<Voter*> RegLogBook::getVoterList() {
return _voterList;
}
Committee.cpp register voter method
void Committee::RegVoter(RegLogBook logs) {
Voter *newVoter = new Voter();
logs.getVoterList().push_back(newVoter); //The voter is not added to the list
}
I call this in my main()
Election *Election2018 = new Election();
Committee com1 = new Committee();
com1.RegVoter(Election2018->getRegLogBook());