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.
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 ?
Thanks.
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
);
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);
There are issues with binding in MSVC10. This isn't the first post I've seen reporting problems with it. Secondly, it's completely and totally redundant with the introduction of lambdas, and boost::function has been superseded by std::function.
std::vector<Device> devices;
std::function<void (Device&, boost::posix_time::time_duration&)> callback = [&](Device& dev, boost::posix_time::time_duration& time) {
devices.push_back(dev);
};
There is no need to use binding in MSVC10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With