#include <list>
#include <algorithm>
#include <iostream>
using namespace std;
class CTest
{
public:
CTest(int x, int y) { this->x = x; this->y = y; };
~CTest() { };
bool operator == (const CTest &other);
public:
int x;
int y;
};
bool CTest::operator == (const CTest &other)
{
if(this->x == other.x && this->y == other.y)
return true;
else
return false;
}
int main()
{
list < CTest > Test;
list < CTest > :: iterator iter;
Test.push_back(CTest(10, 20));
Test.push_back(CTest(30, 40));
Test.push_back(CTest(50, 60));
iter = find(Test.begin(), Test.end(), CTest(30, 40));
if(iter != Test.end())
cout << iter->x << "\t" << iter->y << endl;
else
cout << "Can't find it!" << endl;
return 0;
}
STL中Vector容器Find的使用(泛型)
最新推荐文章于 2023-05-17 20:25:54 发布