title: Generating functions with macros in C++
body: <p>I have the following macro that is intended to generate functions in the current scope or namespace:</p>
  
  <pre><code>#define MAKE_FUNC(FNAME) \
  template &lt;typename T&gt; \
  T ##FNAME## (const T&amp; t) \
  {\
     return t; \
  }
  
  MAKE_FUNC(foo)
  MAKE_FUNC(boo)
  
  int main()
  {
     foo(1);
     boo(2);
  }
  </code></pre>
  
  <p>The following is the error message when compiling the above code:</p>
  
  <pre><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
  </code></pre>
  
  <p><a href="http://ideone.com/paiu1">http://ideone.com/paiu1</a></p>
  
  <p>It seems like the concatenation has fail, is there anyway around this problem?</p>