Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function Macro Does Not Work

Reply
Thread Tools

Function Macro Does Not Work

 
 
Immortal Nephi
Guest
Posts: n/a
 
      09-04-2009
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;
}
 
Reply With Quote
 
 
 
 
Chris M. Thomasson
Guest
Posts: n/a
 
      09-05-2009
"Immortal Nephi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
}
__________________________________________________ ___________

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function pointer as template argument - does not work for function template avasilev C++ 4 12-22-2011 02:11 PM
Macro does not work in source code. Nephi Immortal C++ 20 08-07-2011 09:15 PM
object-like macro used like function-like macro Patrick Kowalzick C++ 5 03-14-2006 03:30 PM
Webservice works once and then DOES NOT seem to work even though program does not crash Phi! ASP .Net Web Services 1 04-23-2004 08:42 AM
Why this MACRO does not work? Karim Thapa C Programming 7 01-21-2004 07:47 AM



Advertisments