Reputation: 5805
I am experienced with C++, but I only began to learn C++/CLI. I notice the following pattern a lot:
array<String^>^ x;
How do you guys think about this? The way I interpret this is, this is array of strings and we want them all to be on the managed heap and that is why we use String^, but we also want the vector to be on the managed heap and that is why we have
array<something>^.
Correct?
Upvotes: 0
Views: 141
Reputation: 275415
C++cli ref class
must live on the managed heap. Actual non-managed heap instances are blocked.
Both String
and array
are ref class
types, so they must live on the managed heap.
C++, in order to remind the user that these are garbage-collected pointer types, and not literals or traditional pointer types, requires that you end the types with a ^
.
While this is redundant (all instances of array<>
are array<>^
-- hence in C# where there is no such ^
token), the reminder that this is a managed type and not a normal type probably helps when you mix managed and unmanaged code.
Upvotes: 3