万能函数第一版本-针对个数确定参数(第二版本实现参数不定)
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;
}
#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;
}
相关文章推荐
- 在VB中实现向函数传递不定个数参数
- 不定参数函数实现
- 通过printf函数简单实现解析不定参数表
- C++中不定参数的函数实现
- 在VB中实现向函数传递不定个数参数
- 在ios要实现不定参数的函数
- 用va_start() va_end()函数解决不定参数问题(即,fun(...)实现方法)
- C语言不定参数函数实现
- 不定参数函数的实现
- 不定参数函数原理以及实现一个属于自己的printf函数
- 研究不定数量参数的函数并实现一个printf函数
- C/C++下不定参数的函数的实现
- 在VB中实现向函数传递不定个数参数
- 不定参数函数实现(windows)
- 怎样实现数目不定的函数参数
- 不定参数函数的实现
- 不定参数函数实现
- c语言不定参数与printf函数的实现
- va_arg() 实现不定参数函数 返回参数不匹配问题
- VC 不定参数函数 实现