将函数调用运算符“()”进行重载:
#include<iostream> using namespace std; class Add { public: double operator ()(double a,double b); }; double Add::operator() (double a,double b) { return a+b; } int main() { Add f; cout<<f(2.5,3.2)<<endl; return 0; }
输出:5.7
2023-11-05 20:34:22
将函数调用运算符“()”进行重载:
#include<iostream> using namespace std; class Add { public: double operator ()(double a,double b); }; double Add::operator() (double a,double b) { return a+b; } int main() { Add f; cout<<f(2.5,3.2)<<endl; return 0; }