Possible duplicate:
How to make a child of the same virtual function first call its parent virtual function
I have a class hierarchy, where each derived class redefines a given virtual function and starts its implementation by calling it in its parent class. The goal is for each executable implementation to be executed, but I don't like the way I do it.
For example, I have this class:
class base
{
public:
void do_stuff() { do_something(); }
virtual void do_something() { }
};
Then I get this class at several levels:
class derived_10:
public derived_9
{
public:
virtual void do_something()
{
derived_9::do_something();
}
};
I am looking for a solution that will call in sequence when base: do_something () is called, when base :: do_stuff () is called, not expecting derived classes to do it themselves. Do you have an idea how to best get this behavior?