Compiler Error

  • Thread starter Thread starter saiz66
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top