ASIO UDP:类 std::分配器<void>没有名为"construct"的成员
ASIO UDP: class std::allocator<void> has no member named ‘construct’
我遵循此示例来设置异步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)...); }
^
代码:
#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;
}
看起来此错误已固定在:
中- https://github.com/chriskohlhoff/asio/commit/503b8bb172240dfdfd3cf2b986799999165c2223c02a57
看起来使它成为增强1.60
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 助记符和指向成员语法的指针
- 用于访问容器<T>数据成员的正确 API
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 嵌套在类中时无法设置成员数据
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 将函数类成员映射到类本身内部
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 将Ref对象作为类成员
- 将包含C样式数组的对象初始化为成员变量(C++)
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将公共但非静态的成员函数与ALGLIB集成
- 多成员Constexpr结构初始化
- ASIO UDP:类 std::分配器<void>没有名为"construct"的成员