是否有可能为没有附加类型的值进行模板特化?模板值专门化
事情是这样的:
template<typename T>
class foo
{
};
template<>
class foo<0>
{
};
是否有可能为没有附加类型的值进行模板特化?模板值专门化
事情是这样的:
template<typename T>
class foo
{
};
template<>
class foo<0>
{
};
是的,但你要使用无类型模板参数:
template<int i>
class foo
{
};
template<>
class foo<0>
{
};
这是更快地尝试,而不是在这里问的问题。与海湾合作委员会(G ++ 4.6)我得到
temp.cc:7:12: error: type/value mismatch at argument 1 in template parameter list for 'template<class T> class foo'
temp.cc:7:12: error: expected a type, got '0'
因此很明显,答案是否定的
我说“像这样的东西”,这意味着它不能像这样工作:)我需要知道是否有可能使用其他语法。 – Felics
随着告诉你它是没有任何意义的代码。然而,这是可能的:
template<int N>
class foo
{
};
template<>
class foo<0>
{
};
你的模板期望一个类型,会进行大量做什么意义? – GManNickG