title: Is typedef inside of a function body a bad programming practice?
body: <p>I have some class <code>C</code> and want to pass address of its instance and method to some functor in  a test function <code>Test_C_Foo1()</code>. Functor is a template class and I have to provide type of the class method (<code>MEMFN1</code>) as one of its template parameters. I have to define <code>MEMFN1</code> type somewhere but don't want to change <code>C.h</code> and don't want to pollute global namespace with it. I decided to localize <em>typedef</em> as much as possible so put it inside a test-function - within the scope where <code>MEMFN1</code> is actually used. <strong>Is using a typedef inside the function body a good practice?</strong></p>
  
  <p>Standard allows using <em>typedef</em> inside a function body, restricting it only in these particular cases:</p>
  
  <blockquote>
    <p>The typedef specifier shall not be combined in a decl-specifier-seq
    with any other kind of specifier except a type-specifier, and it shall
    not be used in the decl-specifier-seq of a parameter-declaration
    (8.3.5) nor in the decl-specifier-seq of a function-definition (8.4).</p>
  </blockquote>
  
  <p>Here's the code snippet:</p>
  
  <p><strong>C.h:</strong></p>
  
  <pre><code>...
  #include &lt;string&gt;
  ...
  
  class C
  {
  public:
      int foo1(const std::string&amp;);       
  };
  </code></pre>
  
  <p><strong>main.cpp:</strong></p>
  
  <pre><code>...
  #include "C.h"
  ...
  
  void Test_C_Foo1()
  {
     typedef int(C::*MEMFN1)(const std::string&amp;);
  
     C c;   
     Functor1&lt;C, MEMFN1,...&gt; f1(&amp;c, &amp;C1::foo1,...);
     ...
  }
  
  ...
  
  int main()
  {
      Test_C_Foo1();
      return 0;
  }
  </code></pre>