Search code examples
c++qttemplatesstructqlist

QList of templated structures


Consider the following two structures:

template <typename T> struct duplet{
  QString str;
  T value;
}

struct MyObject{
QList<struct duplet> myList;
}

The compiler throws the following error:

error C3203: 'Duplet' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type

Is it syntax error that I am stumbling upon or a an illegal declaration ??

Thanks, de costo


Solution

  • I think its simply that duplet, as a template, must be fully specified in order to serve as a template argument? The compiler can't create the mylist instance because it doesn't know what type it is. 'duplet' is not a (complete) type; 'duplet< T > for some type T' is.

    struct MyObject {
    QList<struct duplet<int> > myList;
    

    and

    template <typename T>
    struct MyObject {
    QList<struct duplet<T> > myList;
    

    compile just fine for me.