Thread: Compiler Error
View Single Post
Old 06-10-2004, 07:03 PM   #8 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Uuhhm wait a minute...
How about you overloading operator< OUTSIDE the Patient class? Do you see why?
Code:
#ifndef PATIENT_H
#define PATIENT_H

class Patient
{	
public:
	Patient(){};
	~Patient(){};
	friend bool operator<(const Patient &T, const Patient &P);
public:
	void setPriority(int priority)
	{ itsPriority = priority; };
	int getPriority()
	{ return itsPriority; };
	void setTime(int time);
	int getTime();
	void setMisdiagnose(int misdiagnose);
	int getMisdiagnose();
private:
	int itsPatientNumber;
	int itsPriority;
	int itsTime;
	int itsMisdiagnose;	
};

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

#endif //PATIENT_H
Do you also understand what the friend keyword means?
Also learn to place private(s) last in the class declaration. Details last
__________________

Last edited by Valmont; 06-10-2004 at 07:47 PM.
Valmont is offline   Reply With Quote