Compile error with QT_STRICT_ITERATORS
Maksim Orlovich
mo85 at cornell.edu
Mon Oct 20 19:24:34 BST 2008
> -------------------------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;".
Overloads are only resolved based on the arguments (including the
receiver), not the return type. Better use constFind.
(You can also do const_cast<const
QMap<QString,QString>&>(strMap).find("blub") but that's rather ugly, to
put it mildly)
-Maks
More information about the kde-core-devel
mailing list