Feb 27, 2019 at 5:41pm
Hi guys,
I learned that you can manage polymorphism with somthing like this for operator<<.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
class Base
{
public:
friend ostream& operator<<(ostream & out,const Base &b)
{return b.Print(out);}
virtual ostream& Print(ostream &out)
{
out<<"This is Base"<<endl;
return out;
}
};
class Derived:Public Base
{
public:
virtual ostream& Print(ostream & out)
{
out<<"This is Derived"<<endl;
return out;
}
};
|
But is it possible to do so for some others with a similar catch?
For == or < or something similar?
Last edited on Feb 27, 2019 at 5:42pm