what is wrong with this template code?

Joined
Jun 8, 2010
Messages
1
Reaction score
0
Consider the following code:

Code:
template <typename T>
class foo
{
 public:
    enum bar {a,b,c};
    bar afunction();
};

template <typename T>
foo<T>::bar foo<T>::afunction(){return a;}

When compiled with gcc 4.4, it throws the error:
Expected initializer before foo
at the afunction definition.

I don't understand why foo<T>::bar in that context does not name a type, this code works well outside a template.

Or, alternately, if you use:

Code:
template <typename T>
class foo
{
 public:
    enum bar {a,b,c};
    bar afunction();
};

template class foo<int>;

foo<int>::bar foo<int>::afunction(){return a;}

It does not complain either...!

Regards.
 
Last edited:

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top