Possible Duplicate:
What does the caret mean in C++/CLI?
In C++/CLR, what does a hat character ^ do?
I created my first Win form application in Visual Studio C++, and browsing through the code saw something that I cannot understand:
private: System::Windows::Forms::Button^ button1;
What is the meaning of ^ sign in this line? I understand * and & but never seen ^ in definition of an object.
Have a look here this is not just C++ but C++/CLI
In C++/CLI the only type of pointer is the normal C++ pointer, and the .NET reference types are accessed through a "handle", with the new syntax ClassName^ instead of ClassName*. This new construct is especially helpful when managed and standard C++ code is mixed; it clarifies which objects are under .NET automatic garbage collection and which objects the programmer must remember to explicitly destroy.
It designates a garbage collected pointer. The normal C++ version is * for pointers, C++/CLI uses ^ to differentiate between managed and unmanaged. It also uses a different keyword to allocate the memory.
int* plain_cpp = new int;
delete plain_cpp; // unmanaged
int^ cpp_cli = gcnew int;
// managed, no delete possible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With