I have a inheritence program where I have a Quote object and in the Quote object I overload the << operator
to handle output. When I use the operator<< with a Quote object it works perfectly.
However, I create a derived object (Quote_Sig) which is the same as the Quote but I add a field to the end of the
object. I then overload the operator<< again to handle this new field.
now when I try to print out the derived class I get the output from the base class.
While it's often useful to think of friend functions as member methods, they aren't really. The compiler see's you are calling operator<< with a reference to the base class, so it uses the operator it knows for the base class. Simple solution: Declare a protected virtual printOn(ostream&) method, and a single <<operator for a base class reference that calls the printOn method on the passed reference.
In the base class I overload the << and create a protected virtual printOn(ostream&) method
In this method I would use the overloaded << to create the ouput.
Then in the derived class I would overload the printOn(ostream&) to output the additonal field? In this overloaded printOn (ostream&), I am not sure what I would put in here.