Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
962 views
in Technique[技术] by (71.8m points)

c++ - 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 . I use Xcode 4.6.3 and in the compiler settings I have this defined:

C++ Language dialect: GNU++11[-std=gnu++11]
C++ Standard Library: libc++(LLVM C++ standard library with C++11 support)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to have BOOST_ASIO_HAS_MOVE defined before including the ASIO headers. If you don't, move support is disabled. See asio/basic_stream_socket.hpp.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...