Question

I have something like this

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;

Error I get says: :16: error: expected constructor, destructor, or type conversion before ‘*’ token

Was it helpful?

Solution

template<class T>
class Outer {
public: 

    class Inner;

    static Inner* x;

    //...

    class Inner {
        //...
    };
};

template<class T>
typename Outer<T>::Inner *Outer<T>::x = NULL;
  1. As for typename and class, please refer to C++ difference of keywords 'typename' and 'class' in templates

  2. Why this, please refer to Trouble with dependent types in templates

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top