在 c++ iso 2003/2011 [temp.expl.spec]/4 中写道
类模板的成员函数、成员类或静态数据成员可以显式地特化为隐式实例化的类特化;在这种情况下,类模板的定义应在类模板成员的显式特化声明点的范围内。如果类模板成员的这种显式特化命名了一个隐式声明的特殊成员函数(第 12 条),则该程序是非良构的。
因此,据我了解,应在显式专门化之前定义允许专门化的特殊功能。
template <typename T>
class A
{
public:
A()
{ /* some definition */}
};
template <>
A<int>::A()
{ /*explicit specialization def body*/} // this is OK
但
template <typename T>
class B
{};
template <>
B<int>::B()
{ /*explicit specializationdef body */} // this is forbidden by ISO c++
// and when compiling with VS2013 gives compile error
// cannot define a compiler-generated special member
// function (must be declared in the class first)
有这样的限制的原因是什么?