码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-03-13 21:01:22      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:重载   ring   ext   pre   pause   print   仿函数   ++   end   

#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;
}

 

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

标签:重载   ring   ext   pre   pause   print   仿函数   ++   end   

原文地址:https://www.cnblogs.com/lyt888/p/12488625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!