[Interest] Strange problem in template class (Iterator as value type of a QHash)

Konstantin Tokarev annulen at yandex.ru
Fri Aug 23 15:05:07 CEST 2013


23.08.2013, 16:43, "Mandeep Sandhu" <mandeepsandhu.chd at gmail.com>:
> Hi All,
>
> I'm writing a template class which contains a QHash. Now if I try to store an Iterator (of a QList) as the _value_ of this Hash then it fails to compile.
>
> Here's the sample code:
>
> template <typename K, typename V>
> class TemplateTest
> {
> public:
>     TemplateTest()
>     {
>         QHash<K, QLinkedList<V>::iterator > h;
>         Q_UNUSED(h);
>     }
>
> private:
>     K k;
>     V v;
> };

Error from Clang:

 error: template argument for template type parameter must be a type; did you forget 'typename'?

Note: use proper compiler next time.


> Error:
>
> templatetest.h:13: error: type/value mismatch at argument 2 in template parameter list for 'template<class Key, class T> class QHash'
> templatetest.h:13: error:   expected a type, got 'QLinkedList<V>::iterator'
> templatetest.h:13: error: invalid type in declaration before ';' token
>
> However, if I keep the value as a QList (remove iterator) it compile fine.
>
> Whats the problem with storing a Iterator as the value?
>
> Thanks,
> -mandeep
>
> ,
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest


-- 
Regards,
Konstantin



More information about the Interest mailing list