Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ^ in object definition? [duplicate]

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.

like image 360
Kamyar Souri Avatar asked Dec 01 '25 10:12

Kamyar Souri


2 Answers

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.

like image 195
Emond Avatar answered Dec 04 '25 06:12

Emond


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
like image 23
Xeo Avatar answered Dec 04 '25 07:12

Xeo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!