weak_ptr和unique_ptr一起工作吗?

Jer*_*ahB 2 c++ smart-pointers weak-ptr unique-ptr c++14

据我所知,a std::weak_ptr被用作引用std::shared_ptr可能已被解除分配的引用的内存的安全方式.可以和它一起使用std::unique_ptr吗?

Sla*_*ica 5

据我所知,std :: weak_ptr用作引用shared_ptrs引用的内存的安全方式,可能已被解除分配.

你理解错了.std::weak_ptr允许访问对象,通过std::shared_ptr不共享来维护所有权.现在当你真正理解std::weak_ptr你应该理解什么时,你的问题std::unique_ptr没有任何意义.