逻辑运算符重载格式
bool operator&&(data1&a,data2&b)
{if(a.a&&b.a){return true;}elsereturn false;
}
举例使用单目运算符重载
#include "iostream"using namespace std;class data1
{public :int a;data1(int a):a(a){}
};class data2
{public :int a;data2(int a):a(a){} };bool operator&&(data1&a,data2&b)
{if(a.a&&b.a){return true;}elsereturn false;
}int main()
{data1 a(20);data2 b(10);if(a&&b){cout << "ture" << endl;}else{cout << "false" << endl;}}