c++ - Pre/Post function call implementation -


I was wondering if I could call functions in some way C ++ Along with a wrapper class, and after each cover function call, I should always call the second function.

So I do not want to call every one of those postfunctions () functions like this:

  square fu {f1 (); F2 (); F3 (); . . . Fn (); } Zero Foo :: F1 () {:: f1 (); PostFunction (); } Zero Foo :: F2 () {:: f2 (); PostFunction (); } e.t.c.  

Instead, I want the post function call to come automatically when I call the FU member function. Is this possible? This will help in maintenance ..

There may be a case! Do-Dunn-Dunn!

{f1} f1 {f1} (foo): foo (foo) {} // pre-function, if you need it, then zero operators () () {} // main function ~ F1 () {} // Post Function Private: Foo & amp; Foo; }

Then you have to make sure every time you want to create a new temporary F1 object to call the function. Reusing it means that pre-post functions are not always said every time.

This can also be wrapped like this:

  zero call_f1 (foo and foo) {f1 (foo) (); // Call constructor (pre), operator () (function only) and destructor (post)}  

You can experiment with other methods of structuring it, but in general See if you can not take heavy load for constructor / destructors for you.

A good idea of ​​Roman M's approach may be to write a generic cover, which takes a fun or function pointer as its logic. In this way, you can call pre / post function before and before calling its logic


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -