tags:

views:

48

answers:

1

I have code similar to the following in a header file:

template<class A>
class List {
  private:
    QVector<A> _list;
};

where QVector is the standard QT container.

When I try to make a variable of type List as a member variable in another header file like this:

class Model {
  private:
    List<int *> the_list;
};

I get the following error:

In instantiation of 'List<int *>':
instantiated from here
error: 'List<A>::_list' has incomplete type

Basically, I want a custom list that is templatized that uses an internal QVector to store the data items.

I assume that my syntax is a little off, so any help would be appreciated.

+2  A: 

Make sure you have #included the header file for QVector before your declaration of class List { }. If you omit it then QVector is an undefined type but because List is a templated class the compiler doesn't omit an error message until you instantiate List for the first time.

#include <QVector>

template<class A>
class List {
  private:
    QVector<A> _list;
};
John Kugelman
Thanks! That was the problem. I must need more caffeine if I spent several hours on a missing #include :).
Aaron
Note, many compilers *will* print an error for this, and even if QVector were defined between this declaration and the instantiation, it is still an error.
Potatoswatter
@Potatoswatter, looks like `QVector` was *forward declared*, so the compiler really is disallowed from erroring out early without instantiation of `List<T>`.
Johannes Schaub - litb
@Johannes: I meant in OP's code. The answer is correct.
Potatoswatter