c++ - Replace macro with a function / template -


I want to change the macro with the function / template:

  #define FOO ( F) \ int result = m_Member.f; \ Switch (result) \ {ca ca 1: \ m_pMember1-> F; \         break; Case 2: m_pMember2-> f; \         break; } Class foo {public: zero foo1 (int x, int y) {FOO (foo1 (x, y)}} zero foo2 (int x, double y, zero * z) {FOO (foo2 (x, y)}} Protected: fooA m_Member; Fubi M_emember 1; FooC m_Member2;};  

So my problem is that the macro is passed along with the function name arguments.I used to eat FOO (foo1, x, Y) and then dealing with the variable logic list, the macro will only define a function call. But maybe there is a more elegant solution.

< Div class = "pos In the form of t-text "itemprop =" text ">

, this is not possible.

The problem is that there is a template, by nature, your type of safe type, though, is not. There is nothing in the name of foo2 which limits the type of set which can be applied to it!

To illustrate this problem, a general member Consider the function:

  struct foo {int doit (double x, double y);}  

its type int (Foo: : *) (Double, double) .

Note how the name of the class is the method the type appears in itself.

In this way, you can not bring doit to two unrelated sections ... so I'm afraid you will get some repetition:

  Square foo {public: zero foo1 (int x, int y) {sending (and fooA :: foo1, and fooB :: foo1, and fooC :: foo1, x, y); } Zero foo2 (int x, double y, zero * z) {send (and fooA :: foo2, and fooB :: foo2, and fooC :: foo2, x, y, z); } Private: Template & lt; Typename ... Args & gt; Zero dispatch (int (FU :: * F) (RGS ...), zero (FUU :: * G) (RGS ...), zero (FUE :: H) ..., ARGS .. Args) { Switch ((m_Member. * F) (Argus ...)) {Case 1: (m_Member1. * G) (Args ...); Return; Case 2: (m_Member2. * H) (Args ...); Return; }} FooA m_Member; Fubi M_emember 1; FooC m_Member2; };  

And yes.


Comments