如何用内部类的类型初始化模板类中的静态字段
How to initialize static field in template class with type of inner class
我有这样的东西
template <class T>
class Outer {
public: class Inner;
static Inner* x;
//...
class Inner {
//...
};
};
// Not working
template <class T>
Outer<T>::Inner* Outer<T>::x = NULL;
我得到的错误说::16: error: expected constructor, destructor, or type conversion before ‘*’ token
template<class T>
class Outer {
public:
class Inner;
static Inner* x;
//...
class Inner {
//...
};
};
template<class T>
typename Outer<T>::Inner *Outer<T>::x = NULL;
对于
typename
和class
,请参考c++中keywords 'typename'和& # 39;类# 39;在模板为什么会这样,请参考模板中依赖类型的问题
相关文章:
- 链接器找不到在虚拟类 c++ 中访问的静态字段的符号
- 如何正确实例化静态字段 tat 是另一个类对象
- C++ 每个派生类的分隔静态字段
- 访问另一个类(系统)的非静态字段,就好像它是我自己的字段一样 - 优雅地
- 类内非静态字段初始化 + 对象池 - >降低可维护性/可读性
- 在模板专业化期间,如何设置C 结构中的静态字段
- 初始化静态字段
- 自动复制=按值并支持多态性的适当类型的非静态字段
- 在抽象类中,可以使用抽象类A的类型创建一个静态字段
- 使2个非静态字段(即动态数组)相互接近使用内存
- C :初始化成员结构的静态字段的正确方法
- 在C++实例中,字段不会初始化为其默认值.静态字段怎么样
- 类的第二个实现文件中静态字段的C++外部
- 为什么 C++ 类需要在类范围之外定义静态字段(数据成员)
- 静态字段链接器错误
- 来自 gcc 原子标头的对我的类静态字段错误的未定义引用
- 静态字段的析构函数.辛格尔顿实现
- 作为静态字段的Singleton实例与getInstance()方法中的静态变量
- "Undefined reference"尝试引用静态字段
- C++中模板类中的静态字段初始化