 == << 示例)
这里说一下如果类或结构体重载()后因其调用方式与函数相似所以称这种为仿函数#include iostream using namespace std; /* run this program using the console pauser or add your own getch, system(pause) or input loop */ class a{ public: int operator()(int a,int b) { return ab; } }; struct b{ int x; int operator(int a){//重载 xa; coutxxendl; return a; } bool operator(b a){//重载 return xa.x; } }; int main(int argc, char** argv) { //类 重载() 调用示例 a m; coutm(2,3)endl; //结构体 重载 调用示例 b n1,n2; n12; coutn1.xendl; n23; //结构体 重载 调用示例 1 if(n1n2){ couttrueendl; } else coutfalseendl; //结构体 重载 调用示例 2 n13;//给n1重新赋值 if(n1n2){ couttrueendl; } else coutfalseendl; return 0; }