I'd rather implement a non-friend function and directly mark the function as virtual.
But I'm in a situation where I'd like to ensure that a specific set of classes implement an overloading of
friend std::ostream& operator << (std::ostream& os, MyClass& myClass);
and I found no other way to link it directly to my class. (Other possibility of implementation of operator is moving it outside my class, without friend)
Syntax lords, do I have any way of properly implementing this rule ? (having children overriding << ostream operator)
Edit - Related subjects on following threads:
Overloaded stream insertion operator (<<) in the sub-class
virtual insertion operator overloading for base and derived class.