重载 () 运算符

来源:互联网 发布:西门子编程器 编辑:程序博客网 时间:2024/04/28 11:23

 

class CMyAverage  {  public:
double operator()( int a1, int a2, int a3 ) { //重载 () 运算符
return (double)(a1 + a2+a3) / 3;
}
 
};  // 重载 () 运算符时,参数可以是任意多个
o CMyAverage Average;  //函数对象
o cout << Average(3,2,3); // Average.operator(3,2,3) 用起来看上去象函数调用
o输出 2.66667