【发布时间】:2021-10-04 15:35:08
【问题描述】:
我有一个使用nghttp2 创建的http 服务器。在此服务器中,我尝试使用 boost 的 circular_buffer 数据结构。
这是我试图在 Ubuntu 20.04 上编译的 C++ 程序。
#include <iostream>
#include <nghttp2/asio_http2_server.h>
#include <boost/circular_buffer.hpp>
using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server;
int main(int argc, char *argv[]) {
boost::circular_buffer<request> buffer(3);
boost::system::error_code ec;
http2 server;
server.handle("/", [&buffer](const request &req, const response &res) {
buffer.push_back(req);
});
if (server.listen_and_serve(ec, "localhost", "3000")) {
std::cerr << "error: " << ec.message() << std::endl;
}
}
我用这个命令编译这段代码:
g++ -std=c++14 server.cc -o server -lnghttp2_asio -lboost_system -lcrypto -lpthread -lssl -lboost_thread
当我编译这个时,我得到以下错误输出
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
from /usr/include/c++/9/bits/allocator.h:46,
from /usr/include/c++/9/string:41,
from /usr/include/c++/9/bits/locale_classes.h:40,
from /usr/include/c++/9/bits/ios_base.h:41,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from http-server.cc:1:
/usr/include/c++/9/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = nghttp2::asio_http2::server::request; _Args = {const nghttp2::asio_http2::server::request&}; _Tp = nghttp2::asio_http2::server::request]':
/usr/include/c++/9/bits/alloc_traits.h:482:2: required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = nghttp2::asio_http2::server::request; _Args = {const nghttp2::asio_http2::server::request&}; _Tp = nghttp2::asio_http2::server::request; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<nghttp2::asio_http2::server::request>]'
/usr/include/boost/circular_buffer/base.hpp:1427:59: required from 'void boost::circular_buffer<T, Alloc>::push_back_impl(ValT) [with ValT = const nghttp2::asio_http2::server::request&; T = nghttp2::asio_http2::server::request; Alloc = std::allocator<nghttp2::asio_http2::server::request>]'
/usr/include/boost/circular_buffer/base.hpp:1474:9: required from 'void boost::circular_buffer<T, Alloc>::push_back(boost::circular_buffer<T, Alloc>::param_value_type) [with T = nghttp2::asio_http2::server::request; Alloc = std::allocator<nghttp2::asio_http2::server::request>; boost::circular_buffer<T, Alloc>::param_value_type = const nghttp2::asio_http2::server::request&; boost::circular_buffer<T, Alloc>::value_type = nghttp2::asio_http2::server::request]'
http-server.cc:16:24: required from here
/usr/include/c++/9/ext/new_allocator.h:145:20: error: use of deleted function 'nghttp2::asio_http2::server::request::request(const nghttp2::asio_http2::server::request&)'
145 | noexcept(noexcept(::new((void *)__p)
| ^~~~~~~~~~~~~~~~~~
146 | _Up(std::forward<_Args>(__args)...)))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from http-server.cc:2:
/usr/local/include/nghttp2/asio_http2_server.h:39:7: note: 'nghttp2::asio_http2::server::request::request(const nghttp2::asio_http2::server::request&)' is implicitly deleted because the default definition would be ill-formed:
39 | class request {
| ^~~~~~~
/usr/local/include/nghttp2/asio_http2_server.h:39:7: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = nghttp2::asio_http2::server::request_impl; _Dp = std::default_delete<nghttp2::asio_http2::server::request_impl>]'
In file included from /usr/include/c++/9/memory:80,
from /usr/local/include/nghttp2/asio_http2.h:29,
from /usr/local/include/nghttp2/asio_http2_server.h:28,
from http-server.cc:2:
/usr/include/c++/9/bits/unique_ptr.h:414:7: note: declared here
414 | unique_ptr(const unique_ptr&) = delete;
| ^~~~~~~~~~
In file included from /usr/include/boost/circular_buffer.hpp:58,
from http-server.cc:3:
/usr/include/boost/circular_buffer/base.hpp: In instantiation of 'void boost::circular_buffer<T, Alloc>::replace(boost::circular_buffer<T, Alloc>::pointer, boost::circular_buffer<T, Alloc>::param_value_type) [with T = nghttp2::asio_http2::server::request; Alloc = std::allocator<nghttp2::asio_http2::server::request>; boost::circular_buffer<T, Alloc>::pointer = nghttp2::asio_http2::server::request*; boost::circular_buffer<T, Alloc>::param_value_type = const nghttp2::asio_http2::server::request&; boost::circular_buffer<T, Alloc>::value_type = nghttp2::asio_http2::server::request]':
/usr/include/boost/circular_buffer/base.hpp:1423:13: required from 'void boost::circular_buffer<T, Alloc>::push_back_impl(ValT) [with ValT = const nghttp2::asio_http2::server::request&; T = nghttp2::asio_http2::server::request; Alloc = std::allocator<nghttp2::asio_http2::server::request>]'
/usr/include/boost/circular_buffer/base.hpp:1474:9: required from 'void boost::circular_buffer<T, Alloc>::push_back(boost::circular_buffer<T, Alloc>::param_value_type) [with T = nghttp2::asio_http2::server::request; Alloc = std::allocator<nghttp2::asio_http2::server::request>; boost::circular_buffer<T, Alloc>::param_value_type = const nghttp2::asio_http2::server::request&; boost::circular_buffer<T, Alloc>::value_type = nghttp2::asio_http2::server::request]'
http-server.cc:16:24: required from here
/usr/include/boost/circular_buffer/base.hpp:2413:14: error: use of deleted function 'nghttp2::asio_http2::server::request& nghttp2::asio_http2::server::request::operator=(const nghttp2::asio_http2::server::request&)'
2413 | *pos = item;
| ~~~~~^~~~~~
In file included from http-server.cc:2:
/usr/local/include/nghttp2/asio_http2_server.h:39:7: note: 'nghttp2::asio_http2::server::request& nghttp2::asio_http2::server::request::operator=(const nghttp2::asio_http2::server::request&)' is implicitly deleted because the default definition would be ill-formed:
39 | class request {
| ^~~~~~~
/usr/local/include/nghttp2/asio_http2_server.h:39:7: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>& std::unique_ptr<_Tp, _Dp>::operator=(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = nghttp2::asio_http2::server::request_impl; _Dp = std::default_delete<nghttp2::asio_http2::server::request_impl>]'
In file included from /usr/include/c++/9/memory:80,
from /usr/local/include/nghttp2/asio_http2.h:29,
from /usr/local/include/nghttp2/asio_http2_server.h:28,
from http-server.cc:2:
/usr/include/c++/9/bits/unique_ptr.h:415:19: note: declared here
415 | unique_ptr& operator=(const unique_ptr&) = delete;
| ^~~~~~~~
【问题讨论】:
-
以后,请在您的问题中包含一个问题。您忽略了说明您是否只是要求解释为什么会发生此错误,或者您是否也对解决错误的方法感兴趣。
标签: c++ linux boost ubuntu-20.04