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?

Recommended Answers

All 2 Replies

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.

Perfect - this was what I needed. Many thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.