【发布时间】:2011-08-12 05:51:51
【问题描述】:
我正在尝试移植以下代码。我知道该标准不允许在非名称范围内进行显式特化,我应该使用重载,但我只是找不到在这种特殊情况下应用这种技术的方法。
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;
}
};
【问题讨论】: