相关疑难解决方法(0)

为什么派生的模板类不能访问基本模板类的标识符?

考虑:

template <typename T>
class Base
{
    public:
        static const bool ZEROFILL = true;
        static const bool NO_ZEROFILL = false;
}

template <typename T>
class Derived : public Base<T>
{
    public: 
        Derived( bool initZero = NO_ZEROFILL );    // NO_ZEROFILL is not visible
        ~Derived();
}
Run Code Online (Sandbox Code Playgroud)

我无法用GCC g ++ 3.4.4(cygwin)编译它.

在将这些转换为类模板之前,它们是非泛型的,派生类能够看到基类的静态成员.在C++规范的要求中是否会失去可见性,还是需要使用语法更改?

据我了解,每个实例Base<T>都会有它自己的静态成员" ZEROFILL"和" NO_ZEROFILL",这Base<float>::ZEROFILLBase<double>::ZEROFILL是不同的变量,但我真的不关心; 常量是为了代码的可读性.我想使用静态常量,因为在名称冲突而不是宏或全局方面更安全.

c++ templates c++-faq derived-class

43
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

c++-faq ×1

derived-class ×1

templates ×1