简体   繁体   中英

QSet::find() iterator dereferencing gets “cannot convert ‘this’ pointer” error?

I get the error on trying to access the iterator reference:

QSet<UniqueWord>::iterator iter = uniqueWords.find(word);
iter->addOccurrence(position); // this gets an error

The error I get:

error: C2662: 'UniqueWord::addOccurrence' : cannot convert 'this' pointer from 'const UniqueWord' to 'UniqueWord &' Conversion loses qualifiers

What am I missing?

You're missing that the iterator's operator-> returns a const UniqueWord * , so you're trying to call addOccurrence on a UniqueWord that is const .

See the documentation here:

http://doc.qt.digia.com/qt/qset-iterator.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM