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

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Fri Aug 23 19:31:15 CEST 2013


On Fri, Aug 23, 2013 at 10:24 PM, Constantin Makshin <cmakshin at gmail.com>wrote:

> g++ isn't bad at all, but sometimes its error messages may be quite
> confusing/cryptic.
>
Agreed.

Rather in some cases it _did_ tell me that i needed to prefix 'typename' in
given line, but unfortunately in this stmt it chose a more cryptic message!
:/

-mandeep



> On Aug 23, 2013 8:39 PM, "Mandeep Sandhu" <mandeepsandhu.chd at gmail.com>
> wrote:
>
>>
>>> Error from Clang:
>>>
>>>  error: template argument for template type parameter must be a type;
>>> did you forget 'typename'?
>>>
>>
>> It' right, in that I need to use typename 'somewhere', I just didn't know
>> where (and why).
>>
>> I finally fixed it doing a typedef of this dependent type, which also
>> makes it easy to type! :)
>>
>>
>> template <typename K, typename V>
>> class TemplateTest
>> {
>>     typedef typename QLinkedList<V>::iterator iter;
>>
>> public:
>>     TemplateTest()
>>     {
>>         QHash<K, iter > h;
>>         Q_UNUSED(h);
>>     }
>> ...
>>
>> There's a nice explanation about 'typename' keyword here:
>> http://pages.cs.wisc.edu/~driscoll/typename.html
>>
>>
>>> Note: use proper compiler next time.
>>>
>>
>> Note:  Using g++, which is a _very_ proper compiler. It even has a
>> "-pedantic" switch! ;)
>>
>> $ g++ --version
>> g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
>>
>> Regards,
>> -mandeep
>>
>>
>>>
>>> > 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
>>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130823/78e79cbf/attachment.html>


More information about the Interest mailing list