tags:

views:

2346

answers:

6

I just came across this code and a few Google searches turn up no explanation of this mysterious (to me) syntax.

Hashtable^ tempHash = gcnew Hashtable(iterators_);

IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator();

What the heck does the caret mean? (The gcnew is also new to me, and I asked about that here.)

A: 

It means that it is a reference to a managed object.

1800 INFORMATION
+8  A: 

This is C++/CLI and the caret is the managed equivalent of a * (pointer) which in C++/CLI terminology is called a 'handle' to a 'reference type' (since you can still have unmanaged pointers).

(Thanks to Aardvark for pointing out the better terminology.)

Rob Walker
I've seen it also refered to has a "handle".
Aardvark
Owen
C++/CLI is an extension of regular C++, so yes - it is only for unmanaged references though
1800 INFORMATION
+3  A: 

It means that this is a reference to a managed object vs. a regular C++ pointer. Objects behind such references are managed by the runtime and can be relocated in the memory. They are also garbage-collected automatically.

Franci Penov
+1  A: 

In C++/CLI it means a managed pointer. You can read more about it (and other C++/CLI features) here:

http://en.wikipedia.org/wiki/C%2B%2B/CLI

Mark Ingram
+1  A: 

From MSDN, it looks like the caret means you are getting a handle to the type being created.

http://msdn.microsoft.com/en-us/library/te3ecsc8(VS.80).aspx

Jon Tackabury
+2  A: 

When you allocated managed memory, that memory can be moved around by the garbage collector. The ^ operator is a pointer for managed memory, that continues to point to the correct place even if the garbage collector moves the object it points to.

Joel Coehoorn