在VS2015上没有编译的绑定对象

时间:2015-05-11 12:53:53

标签: c++ boost boost-asio visual-studio-2015 libtorrent

libtorrent中,我发现了以下代码,它不能用Visual Studio 2015 RC编译:

boost::bind( &address::is_v4,
             boost::bind( &tcp::endpoint::address,
                          _1
             )
)
== m_bind_addr.is_v4()

虽然我们可能会讨论使用bind进行运算符重载的可疑用法,但实际上我想知道为什么它不能编译。错误消息是:

C:\Projects\boost\boost/bind/bind.hpp(2003): error C2027: use of undefined type 'boost::_bi::add_cref<Pm,0>'
          with
          [
              Pm=bool (__thiscall boost::asio::ip::address::* )(void) const
          ]
  C:\Projects\boost\boost/bind/bind.hpp(2011): note: see reference to class template instantiation 'boost::_bi::dm_result<M (__thiscall boost::asio::ip::address::* ),A1>' being compiled
          with
          [
              M=bool (void) const,
              A1=boost::_bi::bind_t<boost::asio::ip::address,boost::_mfi::cmf0<boost::asio::ip::address,boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>>,boost::_bi::list1<boost::arg<1>>>
          ]

1 个答案:

答案 0 :(得分:0)

我遇到了这个,但仅限于32位编译。 64位很好。使用mem_fn(来自boost / mem_fn.hpp)将函数包围起来就可以了:

boost::bind( &address::is_v4,
         boost::bind( boost::mem_fn( &tcp::endpoint::address),
                      _1
         )
) == m_bind_addr.is_v4()