重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

花括号操作符重载

#include 
using namespace std;

class Square{
public:
    double operator()(double x)const{
        return x * x;
    }
    int operator()(int a,int b,int c=0)const{
        return a+b-c;
    }
};

int main(void){
    Square sq;
    //括号里面的参数会被自动当作形参传入
    cout << sq(12) << endl; //144
    cout << sq(1,5,3) << endl; //3
    cout << sq(1,3) << endl; //4
    return 0;
}

网页题目:花括号操作符重载
分享网址:http://cqcxhl.com/article/gcdccg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP