I'm growing increasingly confused by the '^' symbol. I have been able to track it down on various sites but there is no real "definition" of it and its usage anywhere.

I am creating a .NET project these days and I bumped into the symbol for the first time in the main method:

int Main(array<String^>^ args){
// Code
return 0;

After a while I understood it was some "top level" operator. For example, the code

Form mainwindow = gcnew Form()

Will generate an error that you have to use the "top level" modifier '^'. So it is solved by doing..

Form^ mainwindow = gcnew Form()

So I have many questions popping in my head about this.. For example, it looks like a pointer declaration, but it clearly is not the same thing (or else they'd just use '*').

-- Is "mainwindow" variable a pointer? (It is used as a pointer.. with the -> operator)
-- Why do you have to use '^'?

In short... Can anyone explain exactly what the '^' operator is and why it is there?

6 Years
Discussion Span
Last Post by memstick

It's called a "handle" which should make searching for info on it a little easier.

Here is a good reference: http://www.functionx.com/cppcli/handles/Lesson04d.htm

It's basically just a designation that the pointer will be garbage collected (so the variable will be allocated in the "managed heap" -- C++/CLI has both a managed and an unmanaged heap).

String^ is the type for regular ol' strings in C++/CLI so you could have:

String ^ str = "Hello";

It's not a character array either, it must be transformed into one with the toCharArray() method (doesn't put a null at the end).

So the argument array for Main is a handle to an array of string handles.

It's a peculiar dialect of the language for sure.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.