views:

411

answers:

5

Has a new symbol joined the C++ language specification while I was sleeping under a rock?

I just encountered the following question:

http://stackoverflow.com/questions/3621649/restrict-text-box-to-only-accept-10-digit-number-c

Which suggests that the '^' symbol is somehow part of C++ (not in the legacy meaning of a bitwise-XOR)

Is this so?

If so, what does it mean? (I tried to google the question but Google didn't come up with satisfactory answers)

+17  A: 

It is the bitwise exclusive or (xor) operator. For a single bit you have 0 ^ 0 = 1 ^ 1 = 0 and 0 ^ 1 = 1 ^ 0 = 1.

However, in the question you are refering to it is part of Microsoft special syntax for C++ development on the .NET platform known as C++/CLI or It Just Works.

Memory on .NET is garbage collected and references to objects will have to be tracked. This makes it impossible to reference these objects using a normal C++ pointer. This construct is used to declare a variable somewhat similar to a pointer that can reference an object on the managed heap.

^ (Handle to Object on Managed Heap)

Martin Liversage
+5  A: 

In the referenced answer, it's not part of the standard C++ language, it's part of the C++/CLI language that Microsoft cobbled together for .NET interop. In that language, ^ means a "pointer to managed memory."

Joel
+1  A: 

It's not part of Standard C++. It's part of Managed C++ (Microsoft's language much like C++ for .NET). It means "a reference to ----" in much the same way a "*" means "A pointer to -----" is Standard C++.

James Curran
It is part of standard C++, in which it is the bitwise XOR operator.
You
Yeah, and "*" also means "multiply" but that's not what we are talking about here.
James Curran
Ben Voigt
+3  A: 

The '^' syntax refers to a tracking reference in C++/CLI, a Microsoft extension to C++ which enables interaction with managed code.

Stu Mackellar
No, it's not. `%` is a tracking reference. `^` is a tracking handle. (Read the page you linked to.)
Ben Voigt
+5  A: 

In Visual C++, ^ represents a handle to a managed object. Essentially what in C# would be a reference. Allocate them with gcnew instead of new, and they will be garbage collected for you. This is how Visual C++ interacts with the CLI.

Nick Lewis