Compile error with QT_STRICT_ITERATORS

Thiago Macieira thiago at kde.org
Mon Oct 20 19:24:23 BST 2008


Christian Ehrlicher wrote:
>-------------------------8<---------------------
>#define QT_STRICT_ITERATORS 1
>#include <QtCore/QMap>
>#include <QtCore/QString>
>
>int main(int, char**)
>{
>   QMap<QString, QString> strMap;
>   QMap<QString, QString>::const_iterator it = strMap.find("blub");
>
>   return 0;
>}
>-------------------------8<---------------------
>
>Somehow gcc won't use "const_iterator find(const Key &key) const;".

That's normal. The selection of the overload is not done by the return 
type. So the compiler always selects “iterator find(const Key &key)” if 
strMap isn't const. Then you get the conversion error afterwards.

Use constFind.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20081020/5f180da7/attachment.sig>


More information about the kde-core-devel mailing list