Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

C++
List<TopicDetails^>  ^subscriptionTopicDetails = gcnew List<TopicDetails^>();
Posted

1 solution

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 (generic System::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
 
Share this answer
 
v3
Comments
CPallini 13-Aug-15 2:42am    
5.
Sergey Alexandrovich Kryukov 13-Aug-15 2:46am    
Thank you, Carlo.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900