简体   繁体   English

不能使用Boost.Asio的可移动对象

[英]Cannot use movable objects with Boost.Asio

Reading this , I got the impression that this code should work: 读到这个 ,我得到的印象是这段代码应该有效:

class Connection : public std::enable_shared_from_this<Connection>
{
public:
    Connection(tcp::socket&& socket) : socket_(std::move(socket)) {}
private:
    tcp::socket socket_;
};

But the compiler issues this error in the constructor: 但编译器在构造函数中发出此错误:

Call to implicitly-deleted copy constructor of 'tcp::socket' (aka'basic_stream_socket<boost::asio::ip::tcp>')

I have also defined BOOST_ASIO_HAS_MOVE . 我还定义了BOOST_ASIO_HAS_MOVE I use Xcode 4.6.3 and in the compiler settings I have this defined: 我使用Xcode 4.6.3并在编译器设置中定义了这个:

C++ Language dialect: GNU++11[-std=gnu++11]
C++ Standard Library: libc++(LLVM C++ standard library with C++11 support)

You need to have BOOST_ASIO_HAS_MOVE defined before including the ASIO headers. 在包含ASIO标头之前,您需要定义BOOST_ASIO_HAS_MOVE If you don't, move support is disabled. 如果不这样做,则禁用移动支持。 See asio/basic_stream_socket.hpp . 请参见asio/basic_stream_socket.hpp

https://svn.boost.org/trac/boost/ticket/8959 https://svn.boost.org/trac/boost/ticket/8959

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM