3

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.

Community
  • 1
  • 1
Kamyar Souri
  • 1,871
  • 19
  • 29
  • It's a hat pointer. Look here: http://stackoverflow.com/q/500580 – Lumi Dec 17 '11 at 19:41
  • 1
    This is due to the fact that a Windows Forms application is not a C++ program but a C++/CLI (C++ for .NET, if you like) program, which are two different languages (though quite related). If you know about this fact and indeed want to use C++/CLI, then get a good tutorial/book about C++/CLI, as the `^` thing is an essential concept. If not, then rather use some other GUI library for C++. – Christian Rau Dec 17 '11 at 19:45
  • 1
    http://img43.imageshack.us/img43/7285/cface.png – Chris Eberle Dec 17 '11 at 19:51

4 Answers4

4

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.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • +1 The only answer taking the probable chance into account that the OP isn't aware of the difference between C++ and C++/CLI. – Christian Rau Dec 17 '11 at 19:47
2

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
Xeo
  • 129,499
  • 52
  • 291
  • 397
1

It's equivalent to a pointer (*) in C++/CLI. One key difference is that it is garbage collected, since C++/CLI is managed.

K Mehta
  • 10,323
  • 4
  • 46
  • 76
0

^ means it is a CLR type and not a C++ native type

Arnon Rotem-Gal-Oz
  • 25,469
  • 3
  • 45
  • 68