c++ - Preprocessor macros -
c++ - Preprocessor macros -
hello facing next problem. lets assume code looks that
#define function1 functionone #define function2 functiontwo #define call_function ( functionname ) \ someobj someobject.... someobject->functionname();
now problem want check function name , depending on want utilize different someobj. phone call of
call_function(function1)
following code called
someobj someobj... someobj->functionone();
but
call_function(function2) .... someobj2 someobj... someobj->functionone();
first of want discourage using answer. comments say, shooting wrong solution problem.
as purpose learning want provide macro solution:
struct someobj1 { void functionone() { std::cout << "someobj1 functionone"; } }; struct someobj2 { void functiontwo() { std::cout << "someobj2 functiontwo"; } }; #define function1 functionone #define function2 functiontwo #define call_function( funcversion ) \ { \ someobj ## funcversion someobj; \ someobj.function ## funcversion (); \ } int _tmain(int argc, _tchar* argv[]) { call_function(1); call_function(2); homecoming 0; }
c++ macros preprocessor
Comments
Post a Comment