我有类似的东西
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
答案 0 :(得分:1)
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