Compiler Error

S

saiz66

I am having a compiler error when running my program. It opens
pqueuebh.cpp(this is a priority queue class my teacher already wrote)
and points to this line of the Insert code

if ( CurrentSize>1 && Element<Array[CurrentSize/2] )

error C2678: binary '<' : no operator defined which takes a
left-hand operand of type 'const class Patient' (or there is no
acceptable conversion)

I am passing my Patient object. What I understand from the error code
is that it has somethign to do with my < operator. But I already
overloaded it. Here is my Patient class with my overloaded operator

class Patient
{

private:
int itsPatientNumber;
int itsPriority;
int itsTime;
int itsMisdiagnose;

public:
Patient();
~Patient();
void setPriority(int priority);
int getPriority();
void setTime(int time);
int getTime();
void setMisdiagnose(int misdiagnose);
int getMisdiagnose();

bool operator <(const Patient &P)
{
if (itsPriority < P.itsPriority)
return true;
else if (itsPriority > P.itsPriority)
return false;
else if (itsTime < P.itsTime)
return false;
else
return true;
}

};

Thanks.
 
S

saiz66

Ok. I got the answer from somebody else.

Replace
bool operator <(const Patient &P)
with
bool operator <(const Patient &P) const


that little const fixed it all.
 
D

doug mansell

Make your operator< function const, like so:

bool operator <(const Patient &P) const


I am having a compiler error when running my program. It opens
pqueuebh.cpp(this is a priority queue class my teacher already wrote)
and points to this line of the Insert code

if ( CurrentSize>1 && Element<Array[CurrentSize/2] )

error C2678: binary '<' : no operator defined which takes a
left-hand operand of type 'const class Patient' (or there is no
acceptable conversion)

I am passing my Patient object. What I understand from the error code
is that it has somethign to do with my < operator. But I already
overloaded it. Here is my Patient class with my overloaded operator

class Patient
{

private:
int itsPatientNumber;
int itsPriority;
int itsTime;
int itsMisdiagnose;

public:
Patient();
~Patient();
void setPriority(int priority);
int getPriority();
void setTime(int time);
int getTime();
void setMisdiagnose(int misdiagnose);
int getMisdiagnose();

bool operator <(const Patient &P)
{
if (itsPriority < P.itsPriority)
return true;
else if (itsPriority > P.itsPriority)
return false;
else if (itsTime < P.itsTime)
return false;
else
return true;
}

};

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top