C++ 仿函数 举例

作者: 赵者也 | 来源:发表于2017-11-05 10:13 被阅读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;
    }
    

    相关文章

      网友评论

        本文标题:C++ 仿函数 举例

        本文链接:https://www.haomeiwen.com/subject/ufscmxtx.html