本文介绍了是否有提高::绑定问题与VS2010?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这下摹编译就好在2010年之前使用code线++和Visual Studio。

I had the following code line which compiles just fine under g++ and Visual Studio prior to 2010.

std::vector<Device> device_list;

boost::function<void (Device&, boost::posix_time::time_duration&)> callback =
  boost::bind(&std::vector<Device>::push_back, &device_list, _1);

其中,设备是一类,没有什么特别的地方。

Where Device is a class, nothing special about it.

现在我升级我的Visual Studio版本2010和编译失败:

Now I just upgraded my Visual Studio version to 2010 and compilation fails with:

Error   1   error C2780: 'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> boost::bind(M T::* ,A1)' : expects 2 arguments - 3 provided C:\developments\libsystools\trunk\src\upnp_control_point.cpp    95

这是怎么回事,我该如何解决这个问题?

What is going on and how can I solve this ?

感谢。

推荐答案

这可能是因为向量::的push_back 现在已经走过支持或2重载的C ++ 0x功能,使得绑定暧昧。

This is probably because vector::push_back now has 2 overloads through support or C++0x features, making the bind ambiguous.

void push_back(
   const Type&_Val
);
void push_back(
   Type&&_Val
);

这应该工作,或使用@ DeadMG的回答提出的内置功能:

This should work, or use the built-in function suggested in @DeadMG's answer:

std::vector<Device> device_list;

boost::function<void (Device&, boost::posix_time::time_duration&)> callback =
  boost::bind(static_cast<void (std::vector<Device>::*)( const Device& )>
  (&std::vector<Device>::push_back), &device_list, _1);

这篇关于是否有提高::绑定问题与VS2010?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:35