I have this line of code:
socket_LWIP = std::make_shared<framework::tcpip::socket::SocketLwip>();
where SocketLwip
is a structure which has this constructor:
SocketLwip();
defined under the :public
section.
I understand that the discussed line of code creates a pointer to this structure, but it is initialized with a ()
which I don't quite understand. What does ()
do?
CodePudding user response:
std::make_shared<T>()
is a template function. The ()
is just its parameter list, like with any other function.
The code in question is simply calling std::make_shared<T>()
, where T
is being set to framework::tcpip::socket::SocketLwip
.
std::make_shared<T>()
creates a new instance of T
, forwarding its own input parameters to T
's constructor (which in this case, there aren't any), and returns that new instance wrapped inside of a std::shared_ptr<T>
object.
That std::shared_ptr<T>
object is then being assigned to the socket_LWIP
variable.