R
Rob McDonald
I would like to force all the classes in my hierarchy to implement the
<< operator for testing purposes. My base class is a pure virtual
class.
I started out by working with operator overloading in the derived
class. I have been trying to use what I learned there to create an
appropriate virtual class to force overloading.
class Base{
// Can't define operator with two arguments inside Base class
virtual std:stream& operator<<(std:stream& s, Base& b) = 0;
// When I did this for the concrete derived class, it failed because
the
// compiler doesn't seem to 'find' the implementation of << for Base
virtual std:stream& operator<<(std:stream& s) = 0;
}
// For the concrete derived class, I got this two-argument approach to
work.
// However, you can't declare virtual functions outside a class.
virtual std:stream& operator<<(std:stream& s, Base& b) = 0;
Any suggestions are appreciated.
Rob
<< operator for testing purposes. My base class is a pure virtual
class.
I started out by working with operator overloading in the derived
class. I have been trying to use what I learned there to create an
appropriate virtual class to force overloading.
class Base{
// Can't define operator with two arguments inside Base class
virtual std:stream& operator<<(std:stream& s, Base& b) = 0;
// When I did this for the concrete derived class, it failed because
the
// compiler doesn't seem to 'find' the implementation of << for Base
virtual std:stream& operator<<(std:stream& s) = 0;
}
// For the concrete derived class, I got this two-argument approach to
work.
// However, you can't declare virtual functions outside a class.
virtual std:stream& operator<<(std:stream& s, Base& b) = 0;
Any suggestions are appreciated.
Rob