Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:20:17+00:00 2026-06-04T08:20:17+00:00

I have the following macro that is intended to generate functions in the current

  • 0

I have the following macro that is intended to generate functions in the current scope or namespace:

#define MAKE_FUNC(FNAME) \
template <typename T> \
T ##FNAME## (const T& t) \
{\
   return t; \
}

MAKE_FUNC(foo)
MAKE_FUNC(boo)

int main()
{
   foo(1);
   boo(2);
}

The following is the error message when compiling the above code:

prog.cpp:8:1: error: pasting "Tfoo" and "(" does not give a valid preprocessing token
prog.cpp:9:1: error: pasting "Tboo" and "(" does not give a valid preprocessing token
prog.cpp:8: error: ISO C++ forbids declaration of ‘Tfoo’ with no type
prog.cpp:9: error: ISO C++ forbids declaration of ‘Tboo’ with no type
prog.cpp: In function ‘int main()’:
prog.cpp:13: error: ‘foo’ was not declared in this scope
prog.cpp:14: error: ‘boo’ was not declared in this scope

http://ideone.com/paiu1

It seems like the concatenation has fail, is there anyway around this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:20:18+00:00Added an answer on June 4, 2026 at 8:20 am

    You want

    T FNAME (const T& t) \
    

    ## concatenates, you don’t want to concatenate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following macro: #define testMethod(a, b) \ if (a.length > b.length) \
I have the following macro: ‎#define GTR(type) \‎ type type##_gtr(type a, type b) \‎
I have following script that executes all the .reg files in the current directory.
I have an Excel worksheet that has the following macro. I'd like to loop
I have the following macro: #define FOREACH(decl, c) BOOST_FOREACH(decl, std::make_pair((c).begin(), (c).end())) (I am using
I'm trying to write a macro that can generate a set of functions that
I have written the following macro, that defines records with a custom string representation.
I have the following C macro from libpurple: #define yahoo_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) &
I have the following couple of C pre-processor macros for creating test functions: //
I have a macro that looks something like this: Foo(x) ((x - '!') &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.