Wolfie7873
Technical User
So, I've learned from the g++ compiler that virtual functions can not be friends, so this leaves me in a quandry.
Typically, when overloading an output operator in a given class, it's common practice to declare the operator globally with the 'friend' keyword giving the function access to the private data members of the class.
When implementing derived classes for proper inheritance and polymorphism, the base class functions are declared as virtual and then properly implemented in the derived classes.
OK, so tell us something we don't know...
If I want to overload the output operator for each derived class but it still be called polymorphically at runtime, how do I do it? i know that I can't declare the original function as a friend. Can I declare it as a member function and everything work ok? I'm so used to declaring overloaded operators as friends that i've hesitated.
Thanks
Eddie
Typically, when overloading an output operator in a given class, it's common practice to declare the operator globally with the 'friend' keyword giving the function access to the private data members of the class.
When implementing derived classes for proper inheritance and polymorphism, the base class functions are declared as virtual and then properly implemented in the derived classes.
OK, so tell us something we don't know...
If I want to overload the output operator for each derived class but it still be called polymorphically at runtime, how do I do it? i know that I can't declare the original function as a friend. Can I declare it as a member function and everything work ok? I'm so used to declaring overloaded operators as friends that i've hesitated.
Thanks
Eddie