模板类:未继承静态成员
Template class: static members not inherited
以下代码
template<int c>
struct Base
{
static const int a = c + 5;
};
template<int c>
struct Derived : Base<c>
{
static const int b = a + 5;
};
由于a was not declared in this scope
。明确指定Base<c>::a
是可行的,但从逻辑上讲,这不应该是必要的,因为我们是从Base<c>
派生的。这是故意的行为(为什么)还是我遗漏了什么?
template<int c>
struct Derived : Base<c>
{
static const int b = Base<c>::a + 5;
};
这实际上取决于编译器,但gcc需要它,当涉及到模板类
时,它就显得很愚蠢相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 如何在C++中使用非静态成员函数作为回调函数
- 如何从另一个文件继承私有成员变量和公共函数
- (C++)为什么静态成员可以在初始化之前使用
- C++继承更改成员
- 类的全局对象和静态成员
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 如何在复杂继承中访问静态成员变量
- 使用 CRTP 进行选择性静态成员继承
- 模板,继承,静态成员增量
- 在C 中,静态成员函数是否继承了?如果是,为什么没有出现歧义错误
- 如何继承静态成员
- 静态成员继承和保护
- C++-Do派生类继承基类的静态成员
- 从外部访问静态成员并通过继承 c++ 访问静态成员
- 让基类的方法使用继承类的静态成员变量...可能?
- 访问2个继承类的静态成员
- 从继承的类实例调用静态成员
- 将继承的成员设置为静态
- 模板类:未继承静态成员