Erroneous '&' error with templates?

P

Paul J. Lucas

Given:

template<typename T> class outer {
public:
class assigner {
public:
assigner& operator=( T const& );
private:
assigner( int index ) : m_index( index ) { }
int const m_index;
friend class outer;
};

assigner operator[]( int i ) {
return assigner( i );
}
};

template<typename T> inline outer<T>::assigner& // line 17
outer<T>::assigner::eek:perator=( T const &value ) {
// ...
return *this;
}

I get:

foo.cpp:17: error: expected initializer before '&' token

using g++ 4.1.2. If I de-template the code, it compiler without error.
So, is this a g++ bug?

- Paul
 
R

red floyd

Given:

     template<typename T> class outer {
     public:
         class assigner {
         public:
             assigner& operator=( T const& );
         private:
             assigner( int index ) : m_index( index ) { }
             int const m_index;
             friend class outer;
         };

         assigner operator[]( int i ) {
             return assigner( i );
         }
     };

     template<typename T> inline outer<T>::assigner&        // line 17
     outer<T>::assigner::eek:perator=( T const &value ) {
         // ...
         return *this;
     }

I get:

     foo.cpp:17: error: expected initializer before '&' token

using g++ 4.1.2.  If I de-template the code, it compiler without error.
So, is this a g++ bug?

No. You need a "typename" between "inline" and "outer" on line 17.

See FAQ 35.18

http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top