tags:

views:

138

answers:

4

Why this doesn't work? (For hell's sake!)

template<class T>
class A
{
    typedef typename T::value_type value_type;
public:
    A();
};

I'm getting following error:
Error 1 error C2825: 'T': must be a class or namespace when followed by '::

But T is a class, I've just specified that didn't I? So what's the problem?
Thanks.

+7  A: 

T could be a primitive type, depending on how you instantiate the template...

Oli Charlesworth
@Oli thanks, I didn't see that in declaration I've had A<int>. Thanks again.
There is nothing we can do
+2  A: 

In which template specialization are you getting this error? Maybe you are doing something like A<int> somewhere in the code. Please give more information about the specialization that gives the error if you want better information.

jbernadas
A: 

Just FYI: Visual C++ only throws such an error if encountering a related problem when actually creating a concrete class from a template. You should be able to determine where that happened rather easily from the error message, and looking into that code might get you a long way to fixing such problems.

karx11erx
+2  A: 

The 'class' keyword has a different meaning when used to specify a template type parameter. In fact, template<class T> and template <typename T> are completely equivilent, and T can be just about any type. Writing template<class T> in no way tells the compiler that T shall be only a class type.

usta