Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ASIO UDP:class std::分配器<;无效>;没有名为‘的成员;建造’;_C++_C++11_Boost_Boost Asio_Asio - Fatal编程技术网

C++ ASIO UDP:class std::分配器<;无效>;没有名为‘的成员;建造’;

C++ ASIO UDP:class std::分配器<;无效>;没有名为‘的成员;建造’;,c++,c++11,boost,boost-asio,asio,C++,C++11,Boost,Boost Asio,Asio,我随后设置了一个异步UDP接收。但它在编译上失败了: g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp 错误消息: In file included from /usr/include/c++/5/ext/alloc_traits.h:36:0, from /usr/include/c++/5/bits/basic_string.h:40, f

我随后设置了一个异步UDP接收。但它在编译上失败了:

g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp
错误消息:

In file included from /usr/include/c++/5/ext/alloc_traits.h:36:0,
                 from /usr/include/c++/5/bits/basic_string.h:40,
                 from /usr/include/c++/5/string:52,
                 from /usr/include/c++/5/stdexcept:39,
                 from /usr/include/c++/5/array:38,
                 from /usr/include/c++/5/tuple:39,
                 from /usr/include/c++/5/functional:55,
                 from /usr/include/c++/5/thread:39,
                 from test1.cpp:1:
/usr/include/c++/5/bits/alloc_traits.h: In instantiation of ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = std::promise<long unsigned int>; _Args = {const std::allocator_arg_t&, std::allocator<void>}; _Tp = void; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<void>]’:
/usr/include/c++/5/bits/shared_ptr_base.h:522:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {const std::allocator_arg_t&, std::allocator<void>}; _Tp = std::promise<long unsigned int>; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:617:4:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = std::promise<long unsigned int>; _Alloc = std::allocator<void>; _Args = {const std::allocator_arg_t&, std::allocator<void>}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {const std::allocator_arg_t&, std::allocator<void>}; _Tp = std::promise<long unsigned int>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr.h:319:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {const std::allocator_arg_t&, std::allocator<void>}; _Tp = std::promise<long unsigned int>]’
/usr/include/c++/5/bits/shared_ptr.h:620:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = std::promise<long unsigned int>; _Alloc = std::allocator<void>; _Args = {const std::allocator_arg_t&, std::allocator<void>}]’
/usr/include/boost/asio/impl/use_future.hpp:39:56:   required from ‘boost::asio::detail::promise_handler<T>::promise_handler(boost::asio::use_future_t<OtherAllocator>) [with Allocator = std::allocator<void>; T = long unsigned int]’
/usr/include/boost/asio/async_result.hpp:62:21:   required from ‘boost::asio::detail::async_result_init<Handler, Signature>::async_result_init(Handler&&) [with Handler = const boost::asio::use_future_t<>&; Signature = void(boost::system::error_code, long unsigned int)]’
/usr/include/boost/asio/datagram_socket_service.hpp:410:51:   required from ‘typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::datagram_socket_service<Protocol>::async_receive_from(boost::asio::datagram_socket_service<Protocol>::implementation_type&, const MutableBufferSequence&, boost::asio::datagram_socket_service<Protocol>::endpoint_type&, boost::asio::socket_base::message_flags, ReadHandler&&) [with MutableBufferSequence = boost::asio::mutable_buffers_1; ReadHandler = const boost::asio::use_future_t<>&; Protocol = boost::asio::ip::udp; typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type = std::future<long unsigned int>; boost::asio::datagram_socket_service<Protocol>::implementation_type = boost::asio::detail::reactive_socket_service<boost::asio::ip::udp>::implementation_type; boost::asio::datagram_socket_service<Protocol>::endpoint_type = boost::asio::ip::basic_endpoint<boost::asio::ip::udp>; boost::asio::socket_base::message_flags = int]’
/usr/include/boost/asio/basic_datagram_socket.hpp:897:51:   required from ‘typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::basic_datagram_socket<Protocol, DatagramSocketService>::async_receive_from(const MutableBufferSequence&, boost::asio::basic_datagram_socket<Protocol, DatagramSocketService>::endpoint_type&, ReadHandler&&) [with MutableBufferSequence = boost::asio::mutable_buffers_1; ReadHandler = const boost::asio::use_future_t<>&; Protocol = boost::asio::ip::udp; DatagramSocketService = boost::asio::datagram_socket_service<boost::asio::ip::udp>; typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type = std::future<long unsigned int>; boost::asio::basic_datagram_socket<Protocol, DatagramSocketService>::endpoint_type = boost::asio::ip::basic_endpoint<boost::asio::ip::udp>]’
test1.cpp:25:28:   required from here
/usr/include/c++/5/bits/alloc_traits.h:530:4: error: ‘using allocator_type = class std::allocator<void> {aka class std::allocator<void>}’ has no member named ‘construct’
  { __a.construct(__p, std::forward<_Args>(__args)...); }
    ^
在/usr/include/c++/5/ext/alloc_traits.h:36:0中包含的文件中,
从/usr/include/c++/5/bits/basic_string.h:40,
来自/usr/include/c++/5/string:52,
从/usr/include/c++/5/stdexcept:39,
从/usr/include/c++/5/array:38,
从/usr/include/c++/5/tuple:39,
from/usr/include/c++/5/functional:55,
从/usr/include/c++/5/thread:39,
来自test1.cpp:1:
/usr/include/c++/5/bits/alloc_traits.h:static void std::allocator_traits::construct(std::allocator_traits::allocator_type&、_Up*、_Args&&…)的实例化中[with _Up=std::promise;_Args={const std::allocator_arg t&,std::allocator};_Tp=void;std::allocator_traits::allocator_traits::allocator_type=allocator_type=std::allocator
/usr/include/c++/5/bits/shared_ptr_base.h:522:39:std:_Sp_counted_ptr_in place::_Sp_counted_ptr_in place(_Alloc,_Args&&…[带_Args={const std::allocator_arg t&,std::allocator};_tpstd::promission;_Alloc=std::Alloc::std::Alloc::allocator;_gnux:_锁策略(锁策略)
/usr/include/c++/5/bits/shared_ptr_base.h:617:4:std::__shared_count::_shared_count(std:_Sp_make_shared_tag,_Tp*,const_Alloc&,cxuargs&…[带有_Tp=std::promission;_Alloc=std::分配器;_Args={std::分配器;_Args={std::分配器}参数={std::分配器},std::分配器};gnu锁策略:(
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35:std::_shared_ptr::_shared_ptr(std:Sp:U make_shared_tag,const_Alloc&,_Args&&…[带Alloc=std::allocator;Args={const std::allocator_arg_t&,std::allocator};Tp=std::promise:GNuX=X=CxGnu锁策略:]
/usr/include/c++/5/bits/shared_ptr.h:319:64:从'std::shared_ptr::shared_ptr(std:'u Sp__make_shared_tag,const_Alloc&,'u Args&&…[带_Alloc=std::allocator;'u Args={const std::allocator_arg&,std::allocator};'u Tp=std::promission]'
/usr/include/c++/5/bits/shared_ptr.h:620:39:必须来自'std::shared_ptr std::allocate_shared(const_Alloc&,,_Args&&…[带_Tp=std::promise;_Alloc=std::allocator;_Args={const std::allocator_arg&,std::allocator}]
/usr/include/boost/asio/impl/use\u future.hpp:39:56:来自“boost::asio::detail::promise\u handler::promise\u handler(boost::asio::use\u future\u t)[with Allocator=std::Allocator;t=long unsigned int]的必填项
/usr/include/boost/asio/async_result.hpp:62:21:boost::asio::detail::async_result_init::async_result_init(Handler&)[with Handler=const boost::asio::use_future_t&;Signature=void(boost::system::error_code,long unsigned int)]
/usr/include/boost/asio/datagram\u socket\u service.hpp:410:51:必须来自“typename boost::asio::async\u result::type boost::asio::datagram\u socket\u service::async\u receive\u from”(boost::asio::datagram_socket_service::implementation_type&,const MutableBufferSequence&,boost::asio::datagram_socket_service::endpoint_type&,boost::asio::socket_base::message_flags,ReadHandler&)[with MutableBufferSequence=boost::asio::mutable\u buffers\u 1;ReadHandler=const boost::asio::use\u future\u t&;Protocol=boost::asio::ip::udp;typename boost::asio::async\u result::type=std::future;boost::asio::datagram\u socket\u service::implementation\u type=boost::asio::detail::reactive\u socket\u服务::实现类型;boost::asio::datagram\uocket\u服务::端点\u类型=boost::asio::ip::基本\u端点;boost::asio::套接字\u基::消息\u标志=int]'
/usr/include/boost/asio/basic_datagram_socket.hpp:897:51:必须来自'typename boost::asio::async_result::type boost::asio::basic_datagram_socket::async_receive_from(const MutableBufferSequence&,boost::asio::basic_datagram_socket::endpoint_type&,ReadHandler&)[with MutableBufferSequence=boost::asio::mutable\u buffers\u 1;ReadHandler=const boost::asio::use\u future\u t&;Protocol=boost::asio::ip::udp;DatagramSocketService=boost::asio::datagram\u socket\u service;typename boost::asio::async\u result::type=std::future;boost::asio::basic\u datagram\u socket::endpoint::endpoint\u
test1.cpp:25:28:从这里开始需要
/usr/include/c++/5/bits/alloc_traits.h:530:4:错误:“using allocator_type=class std::allocator{aka class std::allocator}”没有名为“construct”的成员
{{uu a.构造({uu p,std::forward({uu args)…);}
^
代码:

#包括
#包括
#包括
#包括
#包括
#包括
int main()
{
boost::asio::io_服务ioserv;
boost::asio::ip::udp::endpoint ep(boost::asio::ip::udp::v4(),(ushort)1414);
boost::asio::ip::udp::socket mysocket(ioserv,ep);
boost::asio::socket\u base::reuse\u地址选项(true);
mysocket.set_选项(选项);
boost::asio::ip::udp::端点发送器\u ep;
而(1)
{
std::数组recv_buf;
boost::asio::ip::udp::endpoint sender\u endpoint;
标准:未来记录长度=
mysocket.async\u接收\u自(
boost::asio::buffer(recv_buf),
发送端,

boost::asio::use_future);//看起来此错误已在以下位置修复:


看起来它进入了boost 1.60

什么(boost)版本?在这里很好,它是
Boost版本:1.58.0
。它在魔杖盒中也会出现错误。如何保存在魔杖盒中?非常感谢。顺便问一下,如何保存在魔杖盒中?我无法获得永久链接。我使用
Share
按钮找不到共享按钮。应该登录吗?在使用
Run
后会出现此按钮。这是一个不错的选择工具,谢谢。
#include <thread>
#include <iostream>
#include <future>
#include <boost/array.hpp>
#include <boost/asio/use_future.hpp>
#include <boost/asio.hpp>

int main()
{
    boost::asio::io_service ioserv;
    boost::asio::ip::udp::endpoint ep(boost::asio::ip::udp::v4(),(ushort)1414);
    boost::asio::ip::udp::socket mysocket(ioserv,ep);
    boost::asio::socket_base::reuse_address option(true);
    mysocket.set_option(option);

    boost::asio::ip::udp::endpoint sender_ep;
    while(1)
    {
        std::array<char, 128> recv_buf;
        boost::asio::ip::udp::endpoint sender_endpoint;
        std::future<std::size_t> recv_length =
            mysocket.async_receive_from(
                boost::asio::buffer(recv_buf),
                sender_endpoint,
                boost::asio::use_future); // <<<< line 25: error

        // Do other things here while the receive completes.

        std::cout.write(
            recv_buf.data(),
            recv_length.get()); // Blocks until receive is complete.
    }
    return 0;
}