Reputation: 24685
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.
Upvotes: 0
Views: 291
Reputation: 6869
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.
Upvotes: 2
Reputation: 2311
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.
Upvotes: 0
Reputation: 2600
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.
Upvotes: 2
Reputation: 272687
T
could be a primitive type, depending on how you instantiate the template...
Upvotes: 7