12

这应该是微不足道的,但我似乎找不到它(除非不存在这样的类!)

智能指针的 STL 类(或类集)是什么?

更新

感谢您的回复,
我必须说我很惊讶没有标准实施。

我最终使用了这个: http: //archive.gamedev.net/reference/articles/article1060.asp

4

5 回答 5

14

除了已经提到的 TR1 shared_ptr 之外,STL 中没有引用计数指针。

我建议你使用 boost::shared_ptr (下载 boost 就足够了,没有什么要编译的,它的实现是 header-only)。

您可能还想看看 Loki 库中的智能指针(同样,仅头文件实现)。

有关可用智能指针的概述,请参见

于 2009-03-17T06:54:52.250 回答
9

如果你不想/不能使用 Boost并且你的编译器实现了TR1,你可以使用shared_ptr(从 Boost 借来的):

#include <tr1/memory>

...

std::tr1::shared_ptr<Foo> ptr(new Foo);

std::auto_ptr否则,不,除了vanilla STL之外没有智能指针。

于 2009-03-17T06:49:59.313 回答
3

时间在流逝,在 C++11 中:

std::shared_ptr
std::weak_ptr

等等

于 2014-11-22T00:41:09.787 回答
1

对于 COM 对象,使用CComPtr<>

于 2009-03-17T06:52:32.583 回答
0

在 STL PLUS 中实施了一段时间的替代方案,请参阅源代码伪造

"STLplus was originally intended as a library to extend the STL by providing missing container data structures such as smart-pointers, matrices, trees and graphs."

于 2012-02-25T18:20:28.573 回答