如何解释C ++ / CLI中的^表达式 [英] How to interpret the ^ expression in C++/CLI
本文介绍了如何解释C ++ / CLI中的^表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码库中有以下C ++ / CLI代码。
请你告诉我为什么我们需要使用两个'^'符号。
我的理解是'^'表示指针。
能告诉我如何解释和推断下面的表达。
Hi ,
I have the following code in C++/CLI in my code base.
Could you please let me know why we need to use two '^' symbols.
My understanding is '^' denotes a pointer .
Could you please let me know how to interpret and infer the below expression.
List<TopicDetails^> ^subscriptionTopicDetails = gcnew List<TopicDetails^>();
推荐答案
这是一个托管指针,与C#或VB.NET中的引用类型引用相同。符号^本身被称为对象操作符的句柄:
https://msdn.microsoft.com/en-us/library/yk97tc08.aspx [ ^ ]。
托管指针的C ++ / CLI方法在.NET语言中是唯一的,因为可以在没有引用的情况下使用该对象,因为可以使用托管ref类型的变量名称直接引用该对象。与常规指针的类比表明了通常的堆栈对象存储,但令人惊讶的是,它是一种伪造的,并且无论如何都使用托管堆来完全模拟值语义。您可以在本出版物中阅读: http://www.gotw.ca/publications/C++CLIRationale .pdf [ ^ ]。
为什么代码片段中有两个^?试想一下:涉及两种不同的类型:列表类型(泛型System :: Collecton :: Generic :: List<>
使用泛型实例化为完整类型type参数)和list元素的类型(在您的情况下,是一个泛型参数)。两者都是参考类型。
-SA
This is a managed pointer, same as reference-type reference in C# or VB.NET. The symbol ^ itself is called handle to object operator:
https://msdn.microsoft.com/en-us/library/yk97tc08.aspx[^].
C++/CLI approach to the managed pointers is unique among .NET language, because the object can be used without references, as the object can be referenced directly with name of a variable of the managed "ref" type. The analogy with "regular" pointer suggests the usual object-on-stack storage, but, surprisingly, it's a kind of fake, and the managed heap is used anyway with full simulation of value semantics. You can read about it in this publication: http://www.gotw.ca/publications/C++CLIRationale.pdf[^].
Why two ^ in your code fragment? Just think about it: two different types are involved: the list type (genericSystem::Collecton::Generic::List<>
instantiated to a complete type using a generic type parameter) and the type of the list element (in your case, a generic parameter). Both are reference types.
—SA
这篇关于如何解释C ++ / CLI中的^表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文