Function Macro Does Not Work

I

Immortal Nephi

I wonder why main() is unable to invoke either fn_1 or fn_2 before it
returns zero value to end the program. How can you fix function macro
issue? I know that it does look like C style. How can I convert
function macro to template?


#define FN_NAME( name ) fn_##name
#define FN( name ) void FN_NAME( name )()

FN( fn_1 )
{
cout << "fn_1()" << endl;
}

FN( fn_2 )
{
cout << "fn_2()" << endl;
}

int main()
{
FN( fn_1 );
FN( fn_2 );

system("Pause");

return 0;
}
 
C

Chris M. Thomasson

Immortal Nephi said:
I wonder why main() is unable to invoke either fn_1 or fn_2 before it
returns zero value to end the program. How can you fix function macro
issue? I know that it does look like C style. How can I convert
function macro to template?
[...]

Try something like:
_____________________________________________________________
#include <iostream>


#define FN_NAME( name ) fn_##name
#define FN( name ) FN_NAME( name )()
#define FN_PROTO( name ) void FN( name )


FN_PROTO( fn_1 )
{
std::cout << "fn_1()" << std::endl;
}

FN_PROTO( fn_2 )
{
std::cout << "fn_2()" << std::endl;
}


int main()
{
FN( fn_1 );
FN( fn_2 );

return 0;
}
_____________________________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top