没有匹配函数来调用Std :: find?

Sam*_*uel 3 c++ qt stl

我想做:

std::find(images_map.begin(), images_map.end(), current_rgb));
Run Code Online (Sandbox Code Playgroud)

哪里:

QRgb current_rgb;
QMap<QRgb, MI*> images_map;
Run Code Online (Sandbox Code Playgroud)

但我得到:

error: no matching function for call to 'find(QMap<unsigned int, MI*>::iterator, QMap<unsigned int, MI*>::iterator, QRgb&)
Run Code Online (Sandbox Code Playgroud)

Mar*_*k B 9

原因是因为find期望value_type容器的容量与传入的搜索类型相同find.你只传递了密钥,而不是密钥和值.

相反,find在容器本身上使用该方法(它也具有对数而不是线性时间复杂度的好处).