What is the difference between a handle to an object in Managed C++
such as:
System::String^ str = gcnew System::String();
and the ordinary C++ pointers?
Also how do they relate to references we have in C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are not talking about (the older) Managed C++, but about C++/CLI, right?
In C#, your code is equivalent to
In C++/CLI, a handle to an object is just the same as a reference in C# – you have reference counting, garbage collector etc.
Ordinary C++ pointers, on the other hand, are (in most cases) pointers to unmanaged objects. You can (of course) have C++ pointers to managed objects, just the way you have pointers available in C# (in unsafe code). Look here for a detailed explanation of pointers in C#, and here for some details about pointers in C++/CLI. Those pointers are not handled by the garbage collector.