title: C++ using typedefs in non-inline functions
body: <p>I have a class like this</p>
  
  <pre><code>template&lt; typename T &gt;
  class vector {
    public:
      typedef T &amp;       reference;
      typedef T const &amp; const_reference;
      typedef size_t    size_type;
  
      const_reference at( size_t ) const;
      reference at( size_t );
  </code></pre>
  
  <p>and later in the same file</p>
  
  <pre><code>template&lt; typename T &gt;
  typename vector&lt;T&gt;::const_reference    // Line X
  vector&lt;T&gt;::at( size_type i ) const
  {
      rangecheck();
      return elems_[ i ];
  }
  
  
  template&lt; typename T &gt;
  reference                              // Line Y
  vector&lt;T&gt;::at( size_type i )
  {
      rangecheck();
      return elems_[ i ];
  }
  </code></pre>
  
  <p>Line X compiles fine but Line Y does not compile. The error message from g++ (version 4.4.1) is:</p>
  
  <pre><code>foo.h:Y: error: expected initializer before 'vector'
  </code></pre>
  
  <p>From this I gather that, if I want to have non-inline functions then I have to fully qualify the typedef name as in Line X. (Note that, there is no problem for <code>size_type</code>.)</p>
  
  <p>However, at least to me, Line X looks clumsy. </p>
  
  <p><strong>Is there any alternative approach?</strong></p>