title: How can I create a variable with the same type as a given function?
body: <p>I have a C++ function like</p>
  
  <pre><code>int f( const std::string &amp;s, double d );
  </code></pre>
  
  <p>Now I'd like to create a variable which holds a pointer to <code>f</code>. This variable should have the correct type (<code>int (*)( const std::string &amp;, double )</code> - but I don't want to write out that type explicitely. I'd like to deduce it from <code>f</code> so that I don't repeat the type signature. Eventually, I'd like to be able to write something along the lines of:</p>
  
  <pre><code>TypeOf&lt;f&gt;::Result x = f;
  </code></pre>
  
  <p>To achieve this, I tried to do something like this:</p>
  
  <pre><code>// Never implemented, only used to deduce the return type into something which can be typedef'ed
  template &lt;typename T&gt; T deduceType( T fn ); 
  
  template &lt;typename T&gt;
  struct TypeOf {
      typedef T Result;
  };
  
  // ...
  TypeOf&lt;deduceType(f)&gt;::Result x = f;
  </code></pre>
  
  <p>My hope was that maybe the return type of a function (<code>deduceType</code>, in this case) could be used as a template argument but alas - it seems you can't do that.</p>
  
  <p>Does anybody know how to do this? I'm looking for a C++03 solution.</p>