why when i am overloading similar operators (like operator+() and operator+(const T&) one in parent and other in derived classes i get compilation error
#include <cstdlib>
#include <iostream>
usingnamespace std;
class parent {
public:
virtual parent operator+()const {
wcout << "parent::+()" << endl;
return *this;
}
};
class derived: public parent {
public:
virtual derived operator+(const derived&)const {
wcout << "derived::+(derived)" << endl;
return *this;
}
};
int main(int argc, char** argv) {
derived a, b, c;
a = b+c;
parent d;
d = +c;
return EXIT_SUCCESS;
}
main.cpp: In function 'int main(int, char**)':
main.cpp:26: error: no match for 'operator+' in '+c'
main.cpp:16: note: candidates are: virtual derived derived::operator+(const derived&) const
but if i redefine virtual operator in derived class everything is ok