Calling ostream friend function of base class in c++
c++, iostream
Solution
If you're averse to casting:
ostream & operator<<(ostream & output, const Child &n) {
const Base& b(n);
output<< n.second << b << endl;
return output;
}
By the way, in general it's probably best to leave putting the `std::endl` to stream for the caller.
Problem
So, I have two classes: ``` class Base { private: int number; public: friend ostream & operator<<(ostream & output, const Base &n); } ostream & operator<<(ostream & output, const Base &n) { output<<n.a<<endl; return output; } class Child : Base { private: int second; public: friend ostream & operator<<(ostream & output, const Child &n); } ostream & output<<(ostream & output, const Child &n) { output<<n.second<<Base:: ????<<endl; return output; } ``` My question is, how can i call the friend function of the base class from the child class to output its content: ``` output<<n.second<<Base:: ????<<endl ``` Thanks in advance :)