Faced such a problem that I need to inherit a constructor with the class parameter boost :: asio :: ip :: tcp :: socket Here is the code that I do not compile:

io_service service; class MainSocket : public ip::tcp::socket { public: set<std::shared_ptr<MainSocket>>::iterator iterrator; ~MainSocket(); MainSocket(io_service ser) : ip::tcp::socket(ser){} }; typedef std::shared_ptr<MainSocket> SOCKET_PTR; ... SOCKET_PTR socket(new MainSocket(service)); //Ошибка 

The error text itself:

  ../../Загрузки/boost_1_61_0/boost/asio/detail/noncopyable.hpp:32:3: error: 'boost::asio::detail::noncopyable::noncopyable(const boost::asio::detail::noncopyable&)' is private noncopyable(const noncopyable&); ^ In file included from ../miniserv/main.cpp:10:0: ../../Загрузки/boost_1_61_0/boost/asio/io_service.hpp:185:7: error: within this context class io_service ^ 

Using C ++ 11 C ++ 14 is permissible. How to declare constructor inheritance so that compilation errors do not occur and the code worked as it should? G ++ compiler

  • The issue is resolved. Code: MainSocket (): ip :: tcp :: socket (service) {} - Gravit

1 answer 1

The error should be clear: io_service cannot be copied, it is inherited from noncopyable . Change the way you pass an io_service object to your class (link, pointer, smart pointer, etc.) and the error goes away. It has nothing to do with inheritance.