弱/强引用指针关系

发布于 2024-10-25 02:05:05 字数 150 浏览 3 评论 0原文

我一直在尝试编写自己的弱/强指针,但我并不清楚其中的关系。我遇到的一切似乎都没有说清楚,而且经常有一位医生会反驳另一位医生所说的。谁能详细解释一下弱/强指针关系,也许还有图像或代码示例?

(请不要只是告诉我“使用boost”或“使用tr1”等。这不是作业,我想学习)。

I have been attempting to write my own weak/strong pointer's but I am not clearly understanding the relationship. Everything I seem to come across does not make it and clear and quite often one doc will contridict what another doc says. Could anyone please explain the weak/strong pointer relationship in detail, with maybe an image or code sample also?

(Please do not just tell me to "use boost" or "use tr1", etc. This is not homework, I want to learn).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光倒影 2024-11-01 02:05:05

强指针拥有底层原始指针。它的存在可以使原始指针保持活动状态,因此它不能指向已清理的内容。它的破坏可能会导致原始指针的删除。弱指针只知道原始指针,以及它是否仍然有效。它不会通过现有的方式使原始指针保持活动状态,也不能通过清理来使原始指针消失。

要获得更详细的答案,您需要展示您发现的矛盾或您对定义的特定部分的疑问。

A strong pointer owns the underlying raw pointer. Its existence can keep the raw pointer alive, and as a result it can't point to something that's been cleaned up. Its destruction can cause a delete on the raw pointer. A weak pointer only knows the raw pointer, and whether or not it's still valid. It doesn't keep the raw pointer alive by existing and it can't make the raw pointer go away by being cleaned up.

To get a more detailed answer you would need to show the contradictions you've found or the question that you have about a specific part of the definition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文