Reputation: 69
I am trying to access the function getnoOfkids()
but even though its public I can't, why? I am only able to access the normal queue operations such as size
,emplace
, etc..
#include <iostream>
#include <queue>
using namespace std;
class Family
{
private:
int id, noOfElders, noOfKids;
public:
bool operator ==(const Family &f)
{
if ((this->id!= f.id) || (this->noOfElders != f.noOfElders)||(this->noOfKids != f.noOfKids))
{
return false;
}
return true;
}
bool operator !=(const Family &f)
{
return !(*this==f); //////////////////////
}
Family(int ide=0, int eld=0, int kid=0) {
noOfElders = eld;
noOfKids = kid;
id = ide;
}
Family(const Family &a) {
noOfKids = a.noOfKids;
noOfElders = a.noOfElders;
id = a.id;
}
Family operator=(Family const &a) {
this->id = a.id;
this->noOfElders = a.noOfElders;
this->noOfKids = a.noOfKids;
return *this;
}
int getnoOfkids() const {
return noOfKids;
}
int getnoOfElders() const {
return noOfElders;
}
int getid() const {
return id;
}
void setnoOfKids(int x) {
noOfKids = x;
}
void setnoOfElders(int x) {
noOfElders = x;
}
void setid(int x) {
id = x;
}
friend ostream & operator<<(ostream & out, const Family & a)
{
out << "The id of the travelers are: " << a.id << endl;
out << "The number of elders are: " << a.noOfElders << endl;
out << "The number of kids are: " << a.noOfKids << endl;
return out;
}
friend istream &operator >> (istream &in, Family &a) {
in >> a.id;
in >> a.noOfElders;
in >> a.noOfKids;
return in;
}
};
queue<Family> KidsQueue(queue<Family> &a, queue<Family> &b) {
queue <Family> newA,newB;
queue <Family> result;
queue <Family> newA,newB; queue <Family> result;
while(!a.empty())
{ if(a.getnoOfElders()) }
}
Upvotes: 1
Views: 64
Reputation: 595971
In KidsQueue()
, your a
parameter is an instance of std::queue
holding elements of type Family
. a
itself is not a Family
, so you can't call Family
methods on it. You need to access individual Family
objects inside of the queue to call Family
methods on them, eg:
while (!a.empty())
{
if (a.front().getnoOfElders()) // <-- front() accesses the 1st Family object in the queue
{
...
}
a.pop();
}
Upvotes: 4