cpponyou
- 1
- 0
I have this HW problem, but I cannot figure out what it wants me to do. I don't want anyone to solve it for me, just point me in the right direction.
Suppose that a class hierarchy has a virtual method print
that outputs C's members to the stream ostream. Write one overload of << so that the statement
outputs p's members to the stream out, where p is any object that belongs to a class in the hierarchy.
What I don't understand is the out << p bit. Am I supposed to be able to do
in my main() and have the overload call p.print() ?
Suppose that a class hierarchy has a virtual method print
Code:
class C {
virtual void print( ostream& ) const;
};
that outputs C's members to the stream ostream. Write one overload of << so that the statement
Code:
out << p;
outputs p's members to the stream out, where p is any object that belongs to a class in the hierarchy.
What I don't understand is the out << p bit. Am I supposed to be able to do
Code:
out << p;
in my main() and have the overload call p.print() ?