shared_ptr 在哪里?

2021-12-24 00:00:00 c++ c++11 boost shared-ptr smart-pointers

经过几个小时试图找到 shared_ptr 的位置后,我现在非常沮丧.我看到的示例都没有显示完整的代码以包含 shared_ptr (和工作)的标题.简单地说明 stdtr1 根本没有帮助!我已经下载了提升,但仍然没有出现!有人能帮我确切地告诉我在哪里可以找到它吗?

I am so frustrated right now after several hours trying to find where shared_ptr is located. None of the examples I see show complete code to include the headers for shared_ptr (and working). Simply stating std, tr1 and <memory> is not helping at all! I have downloaded boosts and all but still it doesn't show up! Can someone help me by telling exactly where to find it?

谢谢你让我发泄我的不满!

Thanks for letting me vent my frustrations!

我看到我的标题已更改.对于那个很抱歉.所以...也是因为我不清楚 shared_ptr 是C++ 版本依赖"--> 这就是为什么我没有说明我的环境--> 因此可能是为什么我很难找到它.

I see my title has been changed. Sorry about that. So... it was also because it was not clear to me that shared_ptr is "C++ version dependant" --> that's why I did not state my environment --> therefore probably why it was so difficult for me to find it.

我正在研究 MSVS2008.

I am working on MSVS2008.

编辑 2:我不知道为什么,但是我在到处寻找 shared_ptr 的同时包括 [memory] ??和 [boost/tr1/memory.hpp] 和 [boost/tr1/tr1/memory] ??..当然,我不能.

EDIT 2: I don't know why, but I was including [memory] and [boost/tr1/memory.hpp] and [boost/tr1/tr1/memory] while looking everywhere for the shared_ptr.. of course, i couldn't.

感谢所有回复.

推荐答案

至少有三个地方可以找到shared_ptr:

There are at least three places where you may find shared_ptr:

  1. 如果您的 C++ 实现支持 C++11(或至少 C++11 shared_ptr),则 std::shared_ptr 将在<内存>.

如果您的 C++ 实现支持 C++ TR1 库扩展,那么 std::tr1::shared_ptr 可能会在 (Microsoft VisualC++) 或 (g++ 的 libstdc++).Boost 还提供了一个可以使用的 TR1 实现.

If your C++ implementation supports the C++ TR1 library extensions, then std::tr1::shared_ptr will likely be in <memory> (Microsoft Visual C++) or <tr1/memory> (g++'s libstdc++). Boost also provides a TR1 implementation that you can use.

否则,您可以获取 Boost 库并使用 boost::shared_ptr,它可以在 中找到.

Otherwise, you can obtain the Boost libraries and use boost::shared_ptr, which can be found in <boost/shared_ptr.hpp>.

相关文章