std::make_sharedis preferred in almost every case. However, if you use weak pointers, you can easily get into a “memory leak” situation, where the memory is stored for much longer than you think at first glance (after all, shared_ptrgone).
As long as there is std::weak_ptrone associated with the control unit std::shared_ptr, the control unit must remain. Since it std::make_sharedcreates a single memory allocation for both the control unit and the data, if the control unit remains, the data must also remain. C std::shared_ptrthere are two distributions, therefore they can be cleared independently.
, std::weak_ptr ( ), std::make_shared , . std::weak_ptr, .
++ 4 , . ++, ++ 11/14, .
edit: @midor, std::make_shared. , T , , () {}, (). std::make_shared<std::vector>(10,10) std::vector(10,10) std::vector{10,10}.