Shared_Ptr of socket creation - what is wrong?

你离开我真会死。 提交于 2020-01-02 15:31:48

问题


So I try:

        boost::shared_ptr<tcp::socket> socket =
            boost::make_shared<tcp::socket>(io_service);

As described here. But It bring me an error:

Compiler tells me that it can not turn (

error C2664: 
boost::asio::basic_stream_socket<Protocol>::basic_stream_socket(
    boost::asio::io_­service &))
'boost::asio::io_service *const ' into 'boost::asio::io_service &'
\include\boost\smart_ptr\make_shared.hpp    

What shall I do?


回答1:


You need to pass the io_service as a reference when using make_shared.

boost::shared_ptr<tcp::socket> socket =
            boost::make_shared<tcp::socket>(boost::ref(io_service));


来源:https://stackoverflow.com/questions/5663076/shared-ptr-of-socket-creation-what-is-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!