I am trying to solve a problem when I have some classes in which I need to do some general work, and then a bunch of problem work, and when this is completed, do another processing common to all these classes.
I have a Base and Derived class that has a function called Execute. When I call a derived version of this function, I would like to be able to do some processing common to all my derived classes in the database, and then continue execution in my Derived :: Execute and return to Base :: Execute to finish with some general work .
Is this possible in C ++ and what is the best way to do this?
This is an idea, but it is probably not very workable:
class Base { public: virtual void Execute(); }; Base::Execute() { // do some pre work Derived::Execute(); //Possible???? // do some more common work... } class Derived : public Base { public: void Execute(); }; void Derived::Execute() { Base::Execute(); //Do some derived specific work... } int main() { Base * b = new Derived(); b.Execute(); //Call derived, to call into base and back into derived then back into base }
source share