0

I'm trying to instantiate a C++ template which itself uses another template but the error says that the field is incomplete:

template <typename T> class T1 { };

template <typename T> class T2
{
    public:
        T2<T> t1;
};

class T_int
{
    public:
        T1<int> t1; //works
        T2<int> t2; //error
};

Both templates are fully defined at this point so why is it not possible to use T2 in this case?

EDIT: I'm aware that classes can't contain themselves. I was just completely blind for this typo.

template <typename T> class T2
{
    public:
        T2<T> t1;
};

should have been

template <typename T> class T2
{
    public:
        T1<T> t1;
};
jklmnn
  • 481
  • 1
  • 5
  • 11

0 Answers0