C++ 杂记C++C++2.0

C++ 仿函数 举例

2017-11-05  本文已影响8人  赵者也
#include <iostream>
 
using namespace std;
 
class Multiply{
public:
    double operator()(double x, double y) const {return x*y;}
    double operator()(double x, int y) const {return x*y;}
    double operator()(int x, double y) const {return x*y;}
    int operator()(int x, int y) const {return x*y;}
};
 
int main()
{
    Multiply multiply;
    cout << " 3.6 * 7 = " << multiply(3.6,7) << endl;
    cout << " 3 * 7 = " << multiply(3,7) << endl;
    return 0;
}
上一篇下一篇

猜你喜欢

热点阅读