The list or vector in the STL uses the Find lookup class object correctly

Source: Internet
Author: User

Operator overloading of the key-to-class object

#include "stdafx.h"
#include <vector>
#include <algorithm>

class people
{
Public
int age;
Char name[32];
Public
BOOL operator = = (Const people&t)
{
if (age = = t.age)
{
return true;
}
return false;
}
};

typedef std::vector<people> Mypeople;
typedef mypeople::iterator Mypeopleit;

int _tmain (int argc, _tchar* argv[])
{
using namespace Std;

People m_p1;
Mypeople m_p;
M_p.push_back (M_P1);
Mypeopleit it = Find (M_p.begin (), M_p.end (), M_P1);
if (It! = M_p.end ())
{
printf ("Find it");
}

return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.