我正在尝试移植以下代码。我知道该标准不允许在非名称空间范围内显式专业化,我应该使用重载,但我只是找不到在这种特殊情况下应用此技术的方法。
class VarData
{
public:
template < typename T > bool IsTypeOf (int index) const
{
return IsTypeOf_f<T>::IsTypeOf(this, index); // no error...
}
template <> bool IsTypeOf < int > (int index) const // error: explicit specialization in non-namespace scope 'class StateData'
{
return false;
}
template <> bool IsTypeOf < double > (int index) const // error: explicit specialization in non-namespace scope 'class StateData'
{
return false;
}
};
您只需将成员模板的专业化移到类主体之外即可。
class VarData
{
public:
template < typename T > bool IsTypeOf (int index) const
{
return IsTypeOf_f<T>::IsTypeOf(this, index);
}
};
template <> bool VarData::IsTypeOf < int > (int index) const
{
return false;
}
template <> bool VarData::IsTypeOf < double > (int index) const
{
return false;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)