c++仿函数

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

 

posted @ 2014-04-12 20:28  sxcww  阅读(147)  评论(0编辑  收藏  举报