【发布时间】:2021-11-12 08:22:09
【问题描述】:
假设我想为派生类重载“==”运算符,是否需要在派生类头文件中重写重载,或者有没有办法在.cpp文件中实现运算符重载而不必在头文件中添加任何内容?如果是这样,派生运算符的实现在 .cpp 中会是什么样子?
我的标题是什么样的:
class A
{
public:
A();
~A();
virtual bool operator==(const A &ref) = 0;
protected:
int year;
string note;
}
class B:A
{
public:
B();
~B();
bool operator==(const B &ref); //is this needed or not?
private:
int month, day;
}
【问题讨论】:
标签: c++ oop inheritance operator-overloading