我有两个函子:
class SFunctor {
public:
SFunctor(double a) { _a = a; }
double operator() (double t) { return _a * sin(t); }
private:
double _a;
};
class CFunctor {
public:
CFunctor(double b) { _b = b; }
double operator() (double t) { return _b * cos(t); }
private:
double _b;
};
我想将这些函数中的一个或另一个传递给另一个函数:
double squarer(double x, ??______?? func) {
double y = func(x);
return y * y;
}
在我的主程序中,我想拨打这样的电话:
CFunctor sine(2.);
SFunctor cosine(4.);
double x= 0.5;
double s = squarer(x, sine);
double c = squarer(x, cosine);
我如何指定功能基金,即在它前面代替 ?? _ ?? ?