我有这样的东西
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++ difference of keywords 'typename' and 'class' in templates
关于c++ - 如何使用内部类类型初始化模板类中的静态字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15846114/