How to call overridden methods in all derived classes

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 // which inherit from derived_8 and so on until derived_0
                   // which inherit from base
{
public:
  virtual void do_something()
  {
    // this will also call derived_8::do_something() and so on
    // until base::do_something()
    derived_9::do_something();

    // then, some stuff
  }
};

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?

+5
1

: ++

, , . . ++, , , . , . , , - + .

+3

All Articles