0

I have a class called Person.
I also have a class called Truck, inherited from class Vehicle.

I want to overload the iostream operators for all three classes so that I can do statements such as:

Person a ;
Vehicle b ;
Truck c ;

cin >> a ;
cin >> b ;
cin >> c ;

Is this possible? If so, how?

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by John A
0

>Is this possible?
Yes.

>If so, how?
Just like you would overload the >> operator for any normal class. It doesn't change with inheritance.

0

but when redefining the << and >>, how do I specify which class the overloading pertains to?

all of them start with

ostream & operator<<(ostream & os, const Complex & c)

edit] funny how when you post questions you answer them yourself after re-reading it. Man I feel dumb. Thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.