#include "stdafx.h"
#include <iostream>
#include <string>
//仿函数
//二、class类型的仿函数
//在cpp中,虽然函数指针就是现成的仿函数;然而在很多情况下,如果使用重载了函数调用
//运算符的class类型对象的话,可以给我们带来很多的好处:譬如灵活性、性能甚至两者兼
//备
//例如:
class ConstantIntFunctor
{
private:
int value;//仿函数调用 所返回的值
public:
ConstantIntFunctor(int c):value(c)
{}
//函数调用
int operator() ()
{
return value;
}
};
//使用上面函数对象的客户端函数
void client(ConstantIntFunctor & cif)
{
std::cout<<"call back functor yields "<<cif()<<'\n';
}
int _tmain(int argc, _TCHAR* argv[])
{
ConstantIntFunctor seven(7);
ConstantIntFunctor fortytwo(42);
client(seven);
client(fortytwo);
return 0;
}