不能使用Boost.Asio的可移动物体 [英] Cannot use movable objects with Boost.Asio

查看:146
本文介绍了不能使用Boost.Asio的可移动物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读<一href=\"http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/overview/cpp2011/move_objects.html\">this,我得到了IM pression这code应该工作:

 类连接:公众的std :: enable_shared_from_this&LT;连接GT&;
{
上市:
    连接(TCP ::插座及放大器;&安培;插座):socket_(性病::移动(插座)){}
私人的:
    TCP ::插座socket_;
};

但是,编译器发出此错误在构造函数中:

 通话隐含缺失的TCP套接字::拷贝构造函数(aka'basic_stream_socket&LT;提高:: ASIO ::知识产权:: TCP&GT;')

我还定义 BOOST_ASIO_HAS_MOVE 。我使用的是X code 4.6.3和编译器设置我有这样定义的:

  C ++语言的方言:GNU ++ 11 [-std = GNU ++ 11]
C ++标准库功能:libc ++(LLVM C ++标准与C ++ 11的支持库)


解决方案

您需要有 BOOST_ASIO_HAS_MOVE 包括ASIO头前面定义。如果你不这样做,此举支持被禁用。参见 ASIO / basic_stream_socket.hpp

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

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)

解决方案

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

这篇关于不能使用Boost.Asio的可移动物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆