operator overloading about Abstract class (cpp)

  abstract, c++, class, inheritance, overloading

In student.h file

class Student {
 protected:
  string Name;
  int Stu_num;
 public:
  virtual void print() = 0;
  // constructor...
}

class Grad_Student: public Student {
 private:
  string Lab;
 public:
  void print();
 // constructor...
}

class Undergrad_Student {
 private:
  string Major;
 public:
  void print();
  // constructor...
}

in student.cpp file

bool operator == (const Student& x, const Student& y) {

}

I want to compare child of Student class; Grad and Undergrad.
in main.cpp when i comapre two student class, it doesn’t work..

Grad_Student grad1 = Grad_Student("Max", 11, "Hubo");
Student *std1 = &grad1;

Grad_Student grad2 = Grad_Student("Max", 11, "Hubo");
Student *std2 = &grad2;

cout << (std1 == std2) << endl; // it always prints 0.
cout << (*std1 == *std2) << endl; // I think this line should work, but makes error.

Should i overload operator== in student class?
give me a hint…

Source: Windows Questions C++

LEAVE A COMMENT