#include <iostream>
#include <map>
#include <utility>
using namespace std;
class __ME
{
public:
int age;
__ME()
{
}
__ME(int a)
{
age = a;
}
void Run()
{
if (age)
{
cout << "年龄是" << age << endl;
}
else
{
cout << "run..." << endl;
}
}
};
template <class K, class V>
class value_equals
{
private:
K key;
public:
value_equals(const K &vt) : key(vt)
{
}
bool operator==(map<const K, V> &elem)
{
return elem->first == key;
}
};
int main()
{
map<string, __ME *> *me1 = new map<string, __ME *>();
me1->insert(map<string, __ME *>::value_type("lyl", new __ME()));
me1->insert(map<string, __ME *>::value_type("lx1", new __ME()));
map<string, __ME *>::iterator it = find(me1->begin(), me1->end(), value_equals<string, __ME *>("lyl"));
cout << it->first << endl;
}
这段代码我在编译时 ,提示 error: invalid operands to binary expression 请问是我哪里做错了吗?
你代码里倒数第三行用了find,而find(beg,end,val)是查找等于值val的元素,应该用find_if(beg,end,unaryPred),查找满足一元谓词条件的元素。
最后几行改为:
另外,
应该改为:
记得开头加上