Template constructor in template class must be defined in the class definition?

Viewed 4147

suppose I write a template class with a template constructor, like that.

template<typename T>
class X{


    template<typename S>
    X(X<S> x){}
};

compiles fine. However, when I try to define the constructor outside of the template declaration, like this:

template<typename T>
class X{


    template<typename S>
    X(X<S> x);
};


template<typename T, typename S>
X<T>::X(X<S> y){}

I receive the following error:

error: invalid use of incomplete type ‘class X<T>’

why? Is it not possible to define a template constructor of a template class outside of the class declaration?

3 Answers
Related