开发者

Cannot specialize struct

Why this doesn't work?

template <class T>
struct Low;

template <>
struct Low<int> {};//Here I'm trying to specialize for int开发者_运维百科

int main()
{
Low<1> a;

}


Low<int> a; will work - Your template takes a type not an integral argument.


Low<1> a;

Your class template Low expects TYPE, not INTEGRAL VALUE!

If you want to use that way, you've to define your class template as:

template <int N>
struct Low {};

This allows you to write Low<1>, Low<2>, Low<400>, etc.


If you define Low as,

template <class T>
struct Low;

Then you've to provide a type when instantiating it. For example, Low<char>, Low<unsigned int>, etc.

So notice the difference how they're defined in each case, and how they are instantiated!


There is a difference between Low<1> and Low<int>.

You will need to write a specialization for Low<1>, but that is not possible since the original template takes a type as the first parameter not a value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜