gpt4 book ai didi

c++ - 错误:尝试使用 boost::asio::async_read 读取时, 'const_iterator' 中没有名为 'class boost::asio::mutable_buffer' 的类型

转载 作者:太空狗 更新时间:2023-10-29 21:24:01 26 4
gpt4 key购买 nike

我在使用这段代码时遇到编译错误。这很奇怪,因为它基本上是从我的另一个项目中复制粘贴的。有什么线索是造成这种情况的原因吗?

void Connection::asyncReceiveHeader()
{
Buffer* header = new Buffer(packetHeaderSize);
ba::mutable_buffer buffer = ba::buffer(header->pointer(), header->size());
auto readHandler = bind(&Connection::headerReceived, this, ba::placeholders::error, ba::placeholders::bytes_transferred, header);

ba::async_read(socket, buffer, readHandler); // Comment this line out and it compiles (this is the line 70)
}

错误:

C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp: In instantiation of 'class boost::asio::detail::consuming_buffers<boost::asio::mutable_buffer, boost::asio::mutable_buffer>':
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:209:46: required from 'class boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp>, boost::asio::mutable_buffer, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > > >'
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:526:3: required from 'void boost::asio::async_read(AsyncReadStream&, const MutableBufferSequence&, ReadHandler&&) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >&]'
..\src\network\Connection.cpp:70:45: required from here
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:150:5: error: no type named 'const_iterator' in 'class boost::asio::mutable_buffer'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:247:36: error: no type named 'const_iterator' in 'class boost::asio::mutable_buffer'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp: In instantiation of 'boost::asio::detail::consuming_buffers<Buffer, Buffers>::consuming_buffers(const Buffers&) [with Buffer = boost::asio::mutable_buffer; Buffers = boost::asio::mutable_buffer]':
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:158:60: required from 'boost::asio::detail::read_op<AsyncReadStream, MutableBufferSequence, CompletionCondition, ReadHandler>::read_op(AsyncReadStream&, const MutableBufferSequence&, CompletionCondition, ReadHandler&) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; CompletionCondition = boost::asio::detail::transfer_all_t; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >]'
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:497:61: required from 'boost::asio::detail::read_op<AsyncReadStream, MutableBufferSequence, CompletionCondition, ReadHandler> boost::asio::detail::make_read_op(AsyncReadStream&, const MutableBufferSequence&, CompletionCondition, ReadHandler) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; CompletionCondition = boost::asio::detail::transfer_all_t; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >]'
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:526:3: required from 'void boost::asio::async_read(AsyncReadStream&, const MutableBufferSequence&, ReadHandler&&) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >&]'
..\src\network\Connection.cpp:70:45: required from here
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:157:58: error: 'class boost::asio::mutable_buffer' has no member named 'end'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:157:58: error: 'class boost::asio::mutable_buffer' has no member named 'begin'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:157:58: error: using invalid field 'boost::asio::detail::consuming_buffers<Buffer, Buffers>::begin_remainder_'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:157:58: error: 'class boost::asio::mutable_buffer' has no member named 'begin'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:161:7: error: 'class boost::asio::mutable_buffer' has no member named 'begin'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:162:7: error: using invalid field 'boost::asio::detail::consuming_buffers<Buffer, Buffers>::begin_remainder_'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp: In instantiation of 'boost::asio::detail::consuming_buffers<Buffer, Buffers>::consuming_buffers(const boost::asio::detail::consuming_buffers<Buffer, Buffers>&) [with Buffer = boost::asio::mutable_buffer; Buffers = boost::asio::mutable_buffer; boost::asio::detail::consuming_buffers<Buffer, Buffers> = boost::asio::detail::consuming_buffers<boost::asio::mutable_buffer, boost::asio::mutable_buffer>]':
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:177:67: required from 'boost::asio::detail::read_op<AsyncReadStream, MutableBufferSequence, CompletionCondition, ReadHandler>::read_op(boost::asio::detail::read_op<AsyncReadStream, MutableBufferSequence, CompletionCondition, ReadHandler>&&) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; CompletionCondition = boost::asio::detail::transfer_all_t; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >; boost::asio::detail::read_op<AsyncReadStream, MutableBufferSequence, CompletionCondition, ReadHandler> = boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp>, boost::asio::mutable_buffer, boost::asio::detail::transfer_all_t, boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > > >]'
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:497:61: required from 'boost::asio::detail::read_op<AsyncReadStream, MutableBufferSequence, CompletionCondition, ReadHandler> boost::asio::detail::make_read_op(AsyncReadStream&, const MutableBufferSequence&, CompletionCondition, ReadHandler) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; CompletionCondition = boost::asio::detail::transfer_all_t; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >]'
C:\MinGW\libraries\boost-1.52\include/boost/asio/impl/read.hpp:526:3: required from 'void boost::asio::async_read(AsyncReadStream&, const MutableBufferSequence&, ReadHandler&&) [with AsyncReadStream = boost::asio::basic_stream_socket<boost::asio::ip::tcp>; MutableBufferSequence = boost::asio::mutable_buffer; ReadHandler = boost::_bi::bind_t<void, boost::_mfi::mf3<void, network::Connection, const boost::system::error_code&, unsigned int, network::Buffer*>, boost::_bi::list4<boost::_bi::value<network::Connection*>, boost::arg<1> (*)(), boost::arg<2> (*)(), boost::_bi::value<network::Buffer*> > >&]'
..\src\network\Connection.cpp:70:45: required from here
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:172:32: error: using invalid field 'boost::asio::detail::consuming_buffers<Buffer, Buffers>::begin_remainder_'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:172:32: error: 'class boost::asio::mutable_buffer' has no member named 'begin'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:174:38: error: no type named 'const_iterator' in 'class boost::asio::mutable_buffer'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:175:38: error: no type named 'const_iterator' in 'class boost::asio::mutable_buffer'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:176:5: error: using invalid field 'boost::asio::detail::consuming_buffers<Buffer, Buffers>::begin_remainder_'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:174:38: error: no type named 'const_iterator' in 'class boost::asio::mutable_buffer'
C:\MinGW\libraries\boost-1.52\include/boost/asio/detail/consuming_buffers.hpp:175:38: error: no type named 'const_iterator' in 'class boost::asio::mutable_buffer'

最佳答案

async_read()自由函数的buffer参数需要满足MutableBuffer sequence requirements .你应该使用 mutable_buffers_1而不是 mutable_buffer

void Connection::asyncReceiveHeader()
{
    Buffer* header = new Buffer(packetHeaderSize);
    ba::mutable_buffers_1 buffer = ba::buffer(header->pointer(), header->size());
    auto readHandler = bind(&Connection::headerReceived, this, ba::placeholders::error, ba::placeholders::bytes_transferred, header);

    ba::async_read(socket, buffer, readHandler);
}

关于c++ - 错误:尝试使用 boost::asio::async_read 读取时, 'const_iterator' 中没有名为 'class boost::asio::mutable_buffer' 的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17044988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com