编程语言
首页 > 编程语言> > C++函数调用运算符重载

C++函数调用运算符重载

作者:互联网

#include<iostream>
#include<string>
using namespace std;
class MyPrint
{
public:
    void operator()(string text) {
        cout << text << endl;
    }
};
class MyAdd {
public:
    int operator()(int n1, int n2) {
        return n1 + n2;
    }
};

int main() {
    MyPrint mp;
    mp("hello c++");//仿函数
    cout << MyAdd()(100, 100) << endl;
    system("pause");
    return 0;
}

 

标签:std,string,MyPrint,C++,运算符,函数调用,include
来源: https://www.cnblogs.com/lyt888/p/12488625.html