赞
踩
typedef struct CollectionLevel_s { int collectionPos; int level; }CollectionLevel_t; typedef struct CollectionLevelCount_s { CollectionLevel_t CollectionLevel; int count; bool operator == (const CollectionLevel_t& e) { return (this->CollectionLevel.collectionPos == e.collectionPos) && (this->CollectionLevel.level == e.level); } bool operator == (const int& pos) { return (this->CollectionLevel.collectionPos == pos); } }CollectionLevelCount_t;
使用函数查找的时候,必须重载操作符才可以。
需要重载操作符
bool operator == (const CollectionLevel_t& e) {
return (this->CollectionLevel.collectionPos == e.collectionPos) && (this->CollectionLevel.level == e.level);
}
CollectionLevelCount_t data;
data.count=0;
data.CollectionLevel.collectionPos=10;
data.CollectionLevel.level=1;
std::vector<CollectionLevelCount_t>ve_collectionLevelCount;
auto tmp = find(ve_collectionLevelCount.begin(), ve_collectionLevelCount.end(),data);
if (tmp == ve_collectionLevelCount.end())
{
//没有找到数据
}
else
{
//找到了数据
}
需要重载操作符
bool operator == (const int& pos) {
return (this->CollectionLevel.collectionPos == pos);
}
例子:
//自己准备数据
auto tmp = find(ve_collectionLevelCount.begin(), ve_collectionLevelCount.end(), elem1.collectionPos);
if (tmp == ve_collectionLevelCount.end())
{
//查找到对应的collectionPos对应相等的数据了
}
else
{
//没有找到数据
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。