DEV Community

Discussion on: What's unique pointer in C++

 
dwd profile image
Dave Cridland

Right! If you do that, you will get a double-free, and essentially nothing can protect you (because the m_ptr of each unique_ptr is independent). But also, you don't need to use threads to do it - and it's why best practise with smart pointers is to use std::make_unique:

auto pt = std::make_unique<point<float>>(1.2f, 2.3f, 3.4f, 4.5f);
Thread Thread
 
gapry profile image
Gapry

Hi, Dave Cridland

Thank you for your rely, insights and suggestion!

Best regards, Gapry.