开发者

T is not a class but it is

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

template<class 开发者_Python百科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.


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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜