400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

花括号操作符重载

#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;
}

名称栏目:花括号操作符重载
URL链接:http://mzwzsj.com/article/gcdccg.html

其他资讯

让你的专属顾问为你服务