函数运算符重载

约 0 个字 32 行代码

#include <iostream>
#include <string>
using namespace std;


class MyPrint{
public:
    void operator()(string text){
        cout << text << endl;
    }
};
class MyAdd{
public:
    int operator()(int v1,int v2){
        return v1 + v2;
    }

};

void test1(){
    MyPrint myPrint;
    myPrint("hello world");

    MyAdd myAdd;
    int res = myAdd(10,10);
    cout << res << endl;
}

int main(){
    test1();
    return 0;
}

颜色主题调整

评论区~

有用的话请给我个赞和 star => GitHub stars
快来跟我聊天~