首页 > 编程语言 > 详细

c++仿函数

时间:2014-04-13 02:25:26      阅读:491      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include "iostream"
using namespace std;

template <class T>
struct plus{
    T operator()(const T& a,const T& b) const {return a+b;}

};
int _tmain(int argc, _TCHAR* argv[])
{
    int a=122;
    int b=1213;
    plus<int> plusobj;
    cout<<plusobj(a,b)<<endl;
    //第一个()产生临时对象,第二个调用
    cout<<plus<int>()(a,b)<<endl;
    system("pause");
    return 0;
}
bubuko.com,布布扣

 

c++仿函数,布布扣,bubuko.com

c++仿函数

原文:http://www.cnblogs.com/sklww/p/3661174.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!