If I get this right, you just want to change how the base class works. Why not inherit privately?
Everything in the base class becomes private in the derived class leaving you free to write member functions on the derived class that can to anything you want. Some might just call base class functions, others might do something different, while others may add functionality.
Private inheritance is implementation inheritance. That is, you want the base class implementation but do not want to expose the base class interface.
This is a classic way of fixing broken classes that belong to third parties.
To me it sounded like he wanted to be able to still call the functions as he would fore the base class. for example if he has a base class object and wants it to do something he would do:
baseOb.doSomething();
now he just wants to alter what it does, so he makes a derived class to modify it with conditions so that he can do this:
derivedOb.doSomething();
and get the functionality he wants.
If he inherits privately he wouldn't be able to call the functions in his program. Basically he just wants to override the function, and also include a call to the base classes version.
What if you did something like this:
- class Base
-
{
-
public:
-
void doSomething()
-
{
-
//Something...
-
}
-
};
-
-
class Derived : public Base
-
{
-
public:
-
void doSomething()
-
{
-
// Something else...
-
Base *temp = this;
-
temp->doSomething();
-
}
-
};
-
-
int main()
-
{
-
Derived d;
-
d.doSomething();
-
return 0;
-
}
This will create a pointer to the current object that thinks it's a Base object, which will then call the base classes version of the function. I tested it and it seems to work.
I think his main problem is that his original post, line 16 attempted to call the function like this: Base::doSomething(); which can't be done unless doSomething() is static. You need to invoke it through an object, and so you just need to treat the current object as a base object to get the base function.