title: Get return type of member function without an object
body: <p>I have a number of classes that I cannot modify.  Each has a copy constructor, at least one other constructor, and a function <code>foo()</code> that returns some value.  I want to make a class template that can derive from each of these classes, and has a data member that is the same type as the return type of <code>foo()</code> (sorry if I've got some of the terminology wrong).</p>
  
  <p>In other words, I would like a class template</p>
  
  <pre><code>template&lt;typename T&gt; class C : public T
  {
    footype fooresult;
  };
  </code></pre>
  
  <p>where <code>footype</code> is the return type of <code>T::foo()</code>.</p>
  
  <p>If the base classes all had, say, a default constructor, I could do</p>
  
  <pre><code>decltype(T().foo()) fooresult;
  </code></pre>
  
  <p>(with the C++0x functionality in GCC) but the classes don't have any particular constructor in common, apart from the copy constructors.</p>
  
  <p>GCC also doesn't allow <code>decltype(this-&gt;foo())</code>, though apparently there is a possibility that this will be added to the C++0x standard - does anyone know how likely that is?</p>
  
  <p>I feel like it should be possible to do something along the lines of <code>decltype(foo())</code> or <code>decltype(T::foo())</code> but those don't seem to work: GCC gives an error of the form <code>cannot call member function 'int A::foo()' without object</code>.</p>
  
  <p>Of course, I could have an extra template parameter <code>footype</code>, or even a non-class parameter of type <code>T</code>, but is there any way of avoiding this?</p>