I have a class like this
template< typename T >
class vector {
public:
typedef T & reference;
typedef T const & const_reference;
typedef size_t size_type;
const_reference at( size_t ) const;
reference at( size_t );
and then in the same file
template< typename T >
typename vector<T>::const_reference
vector<T>::at( size_type i ) const
{
rangecheck();
return elems_[ i ];
}
template< typename T >
reference
vector<T>::at( size_type i )
{
rangecheck();
return elems_[ i ];
}
Line X compiles fine, but line Y does not compile. Error message from g ++ (version 4.4.1):
foo.h:Y: error: expected initializer before 'vector'
From this, I understand that if I want to have non-built-in functions, then I must fully qualify the typedef name as on line X. (Note that size_typethere is no problem for that .)
However, at least for me, line X looks awkward.
Is there an alternative approach?
source
share