C++ Boost: initializing endpoint after contructor

前端 未结 1 1471
无人共我
无人共我 2021-01-27 17:44

I try to make a class to use UDP. I want to have the endpoint initialized after the constructor, so I modify it as follows:

class UdpSender
{
private:
    boost         


        
1条回答
  •  清歌不尽
    2021-01-27 18:23

    No. According to the Asio reference, the endpoint object should be configured via its constructors.

    However, you could hold the endpoint by [smart-]pointer, and create it after UdpSender construction.

    // defining:
    private:
        boost::shared_ptr endpoint;
    
    // creating in Initialize()
    endpoint = boost::make_shared(boost::asio::ip::address::from_string(multicast_address), multicast_port);
    

    0 讨论(0)
提交回复
热议问题