i have abstract class (class "father") and son class
i want to write on the father the operator << and implemnt it on the son
here the code
#include <iostream>
using namespace std;
class father {
virtual friend ostream& operator<< (ostream & out, father &obj) = 0;
};
class son: public father {
friend ostream& operator<< (ostream & out, son &obj)
{
out << "bla bla";
return out;
}
};
void main()
{
son obj;
cout << obj;
}
i get 3 error
Error 3 error C2852 : 'operator <<' : only data members can be initialized within a class
Error 2 error C2575 : 'operator <<' : only member functions and bases can be virtual
Error 1 error C2254 : '<<' : pure specifier or abstract override specifier not allowed on friend function
what i can do please?
protected
pure virtual functionstd::ostream& put(std::ostream& os) const = 0;
and a global functionfriend ostream& operator<< (ostream & out, father &obj)
utilizing it. Note thatfriend
relationships aren't inherited.