同时使用VC6和VS2005编译都报同样的错误:代码很简单,
就是定义了一个类,然后用STL list来存储这个类。使用STL泛型算法Find来查找class myClass
{
string strName;
int iSN;
bool operator==(const myClass& r) const;
}代码:
list<myClass> m_List;
.........添加数据;
m_list.push_back();
find(m_List.begin(),m_list.end(),"Name");
//有上面这句就报错代码是简化的,不知道大家有没有见到过这样的问题啊,谢谢啊,急用啊!
请不要嫌分数少啊,多谢!
就是定义了一个类,然后用STL list来存储这个类。使用STL泛型算法Find来查找class myClass
{
string strName;
int iSN;
bool operator==(const myClass& r) const;
}代码:
list<myClass> m_List;
.........添加数据;
m_list.push_back();
find(m_List.begin(),m_list.end(),"Name");
//有上面这句就报错代码是简化的,不知道大家有没有见到过这样的问题啊,谢谢啊,急用啊!
请不要嫌分数少啊,多谢!
find你要提供比较函数或者仿函数
[email protected]
万分感谢!
bool operator==(const myClass& r) const;
试一下改为不用const是否正确。find(m_List.begin(),m_list.end(),"Name");
find的值赋给什么对象,应该是一个const对象
const_iter
Find是STL里面的函数,我看大家用的都是直接输入值啊,
能解释一下吗?
{
string strName;
int iSN;
bool operator==(const myClass& r) const;
} 代码:
list <myClass> m_List;
.........添加数据;
m_list.push_back();
find(m_List.begin(),m_list.end(),"Name");
改为:
myClass tmp;
tmp.strName = "Name";
find(m_List.begin(),m_list.end(),tmp);====================================================
你重载的是==myClass对象,所以find比较的时候当然只能是myClass对象了