在 C++/CLI 中,帽子字符 ^ 的作用是什么?
我正在阅读 Ivor Horton 的 Beginning Visual C++ 2008,它的许多 CLR 示例都有这样的 main 定义:
int main(array<System::String ^> ^args)
我一页一页地回到书的开头,找到第一个这样的实例,并解释了它的真正含义,但是找不到。
显然它的含义与标准 int main(int argc, char *argv[])
相同,但我想知道何时以及为何真正使用 ^
,以及为什么它存在(它是否做了指针 *
和引用 &
无法表示的事情)?
I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main:
int main(array<System::String ^> ^args)
I went back, page by page, to the beginning of the book to find the first such instance with an explanation what it really means, but couldn't find one.
Obviously it means the same as the standard int main(int argc, char *argv[])
, but I'd like to know when and why that ^
is really used, and why it even exists (does it do something that pointers *
and references &
cannot represent)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它是一个托管指针 - 而 * 标记指向非托管对象的指针,而 ^ 指向垃圾收集对象(由框架处理)。 请阅读本文,了解有关 .NET 中处理指针的方式的更多信息。
It's a managed pointer - while * marks a pointer to an object that is unmanaged, ^ points to a garbage collected object (handled by the framework). Read this for more information about the way pointers are handled in .NET.
补充一点,在 C++/CLI 中,托管指针与普通指针分开处理,因此您甚至可以使用不同的关键字来分配它们:
托管对象和本机对象是两个完全不同的东西,您不能混合它们(嗯,不能容易地)。
Just to add to that, in C++/CLI, managed pointers are handled separately from normal pointers, so you even allocate them with a different keyword:
Managed and Native objects are two completely different things and you can't mix them (well, not easily).
有关完整讨论,请参阅:http://msdn.microsoft.com/de- de/library/yk97tc08.aspx:
See this for full discussion: http://msdn.microsoft.com/de-de/library/yk97tc08.aspx: