在我看来,C++在名称空间和全局作用域(MS VSC++错误C3412)之外的任何作用域中都不允许成员模板专用化。但对我来说,在派生类中专门化一个基类的主成员模板是有意义的,因为那是派生类所做的 - 专用于基类中的事物。例如,考虑下面的例子:成员模板专业化及其范围
struct Base
{
template <class T>
struct Kind
{
typedef T type;
};
};
struct Derived : public Base
{
/* Not Allowed */
using Base::Kind;
template <>
struct Kind <float>
{
typedef double type;
};
};
int main(void)
{
Base::Kind<float>::type f; // float type desired
Derived::Kind<float>::type i; // double type desired but does not work.
}
我的问题是为什么它不被允许?
顺便说一句,在g ++中存在确认错误#39906(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39906),它错误地接受了类似的代码。但是,Comeau和VC++没有。 – Sumant 2009-04-30 18:36:47