《C++STL基础及应用》
#include <iostream>
#include<functional>
#include<vector>
#include <numeric>
using namespace std;
//关系运算类函数非常规使用
class Complex
{
public:
float real;
float virt;
public:
Complex()
{
this->real=0.0f;
this->virt=0.0f;
}
Complex(float real,float virt)
{
this->real=real;
this->virt=virt;
}
//前面使用const 表示返回值为const
//后面加 const表示函数不可以修改class的成员,即加号前面的类的成员变量固定
bool operator==(const Complex & c)const
{
return ((real==c.real)&&(virt==c.virt));
}
};
int main()
{
Complex c1(1,2);
Complex c2(3,4);
Complex c3(1,2);
cout<< equal_to<Complex>()(c1,c2)<<endl;
cout<<(c1==c2)<<endl;
cout<<equal_to<Complex>()(c1,c3)<<endl;
cout<<(c1==c3)<<endl;
}
来源:CSDN
作者:ycl010203
链接:https://blog.csdn.net/qq_32140289/article/details/103832388