您的位置:首页 > 其它

万能函数第一版本-针对个数确定参数(第二版本实现参数不定)

2011-12-18 20:53 543 查看
#include <boost/function.hpp>

#include <boost/bind.hpp>

#include <iostream>

void function0(int vParam0, int vParam1)

{

std::cout << "function0:" << vParam0 << std::ends << vParam1 << std::endl;

}

void function1(std::string vParam0, float vParam1)

{

std::cout << "function1:" << vParam0 << std::ends << vParam1 << std::endl;

}

template <typename FuncAddress, typename P0, typename P1>

void excute(FuncAddress vFuncAddress, P0 vParam0, P1 vParam1)

{

typedef boost::function<void(P0, P1)> m_Functor;

m_Functor functor;

functor = boost::bind(vFuncAddress, _1, _2);

functor(vParam0, vParam1);

}

int main(int argc, char **argv)

{

excute(&function0, 2, 1);

std::string Str("hello world");

excute(&function1, Str, 11.0f);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: