Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我今天上了一堂编程课,我的教授提到了智能指针。他说不是每个智能指针都需要一个引用计数器,我有点困惑......在我的理解中,智能指针的使用是在所有指针和对它的引用超出范围后删除分配的内存。我误会了吗?没有引用计数器的智能指针有什么用?
std::unique_ptr是一个没有引用计数器的智能指针的例子。
std::unique_ptr
unique_ptr它保留对象的唯一所有权,并在超出范围时销毁该对象。
unique_ptr