首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于Boost库中boost:function和boost:bind使用的有关问题

2012-05-20 
关于Boost库中boost::function和boost::bind使用的问题大家好,我想请教一个问题。class ABC{static void tr

关于Boost库中boost::function和boost::bind使用的问题
大家好,我想请教一个问题。

class ABC{
 static void transfer_configured_vtn_to_vtn_thread();
}

现在如下使用:
boost::function<void(const int32_t, const int32_t, const uint64_t)>
f= boost::bind(&ABC::transfer_configured_vtn_to_vtn_thread);

这样为什么是可以的呢?
boost::function<void(const int32_t, const int32_t, const uint64_t)>
f 是返回void,以const int32_t, const int32_t, const uint64_t为参数的函数对象。
而boost::bind(&ABC::transfer_configured_vtn_to_vtn_thread)是把
static void transfer_configured_vtn_to_vtn_thread()绑定后的函数对象,是没有参数的啊。
为什么可以赋值呢?

望不吝指教。

[解决办法]
boost做了一个强制转换。

C/C++ code
template<        typename FunctionObj,        typename R BOOST_FUNCTION_COMMA        BOOST_FUNCTION_TEMPLATE_PARMS      >      struct BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER      {        static BOOST_FUNCTION_VOID_RETURN_TYPE        invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA               BOOST_FUNCTION_PARMS)        {          FunctionObj* f;          if (function_allows_small_object_optimization<FunctionObj>::value)            f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);          else            f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);          BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));        }      };
[解决办法]
把void (*)()强制转换成了void (*)(const int32_t, const int32_t, const uint64_t)。
[解决办法]
我觉得你的理解没错。

热点排行