I have a base class Person with 3 instance vars. Person(string name, unsigned long id, string email) and one derived class Student that inherits Person and have one new instance var year Student(string name, unsigned long id,int year,string email): Person(name,id,email) and one class Teacher that isn't necessary to describe.
Then a have the class named eClass
and I want Overload the comparison operator == and use that operator in function bool exists() when I compile my .cpp i have that error
error: cannot define member function 'Student::operator==' within'eClass can anyone help me with that?
Also I don't understand the const
in that function of my code. what that do?
bool Student::operator==(const Student* &scnd)const{... ... ...}
eClass{
private:
Teacher* teacher;
string eclass_name;
Student* students[MAX_CLASS_SIZE];
unsigned int student_count;
public:
eClass(Teacher* teach, string eclsnm){
teacher=teach;
eclass_name=eclsnm;
}
bool Student::operator==(const Student* &scnd)const{
return(getID==scnd.getID
&&getName==scnd.getName
&&getYear==scnd.getYear
&&getEmail==scnd.getEmail);
}
bool exists(Student* stud){
for(int i=0; i<MAX_CLASS_SIZE;++i){
if(stud==students[i]){return TRUE;}
}
return FALSE;
}
}