class A
{
public:
//constructors.....
A operator++(constint& i)
{
a++;
return *this;
}
int a;
}
class B : public A
{
public:
//constructors.....
B operator++(constint& i)
{
/* What happens?? Is there a proper way to write code to avoid this?? */
return *this;
}
int b;
}
The operator I am overloading is a bitshift operator for istream and ostream. It allows the user to save the object in a file nice and neat. I am writing a sub-class of this class that has a few additional functionalities on top of the class it inherits from. It will save data from the oject it inherits from, on top of additional data it uses.
Don't make up examples that demonstrate an entirely different problem than the one you're having.
IWishIKnew wrote:
The operator I am overloading is a bitshift operator for istream and ostream. It allows the user to save the object in a file nice and neat. I am writing a sub-class of this class that has a few additional functionalities on top of the class it inherits from. It will save data from the oject it inherits from, on top of additional data it uses.
You need a virtual serialize member function which operator<< calls.
Are there different circumstances for... these calls??
Also, I'm having trouble finding a clear reference for serialized virtual member function...
I found out that I could over-ride an inherited function by virtualizing it, but that requires I re-write that function (or call it, or make it static or somthing) every time I want to use that function, just with a few additional steps.
It seems like the only difference between the two is that one calls an inherited function through it's scope, and that you're using functions instead of operators.
No, operator<< with std::ostream as its left parameter and and instance of your class as its right parameter must be a global operator, so even if it is in class scope it must be a friend function - it cannot be inherited and does not belong to the class.