0

I have edited this question to make myself clear. My question was.

If we define

String a

we can define characters as a[],

but if we define String ^ a

a[] cant be defined.

So why a[] is not defined if both are strings.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Prajwal Acharya
  • 89
  • 1
  • 2
  • 11
  • It's handle to object operator. It has to be created with `gcnew`. – Andro Nov 12 '14 at 12:11
  • 2
    [What does the caret (‘^’) mean in C++/CLI?](http://stackoverflow.com/questions/202463/what-does-the-caret-mean-in-c-cli) – Piotr Skotnicki Nov 12 '14 at 12:11
  • 1
    std::string is not spelled with a capital letter. System::String is the .NET string type, it has the ^ hat because it is a garbage collected object. – Hans Passant Nov 12 '14 at 12:12

2 Answers2

0

String^ is a handle to underlying string. These are much like pointers/references in C++ except the aid they provide to garbage collector. That means you don't need to delete memory for them as you do for pointers in C++.

ravi
  • 10,994
  • 1
  • 18
  • 36
0

Microsoft's Managed C++ is radically different from the standard definitions you are used to in usual C++. One major difference is the way it handles memory allocation/freeing using managed pointers. The ^ you are referring to is called the hat operator and it is used to denote a pointer whose memory state is managed automatically at run-time. This means you will not have to use delete to free memory previously allocated for it.

While the usefulness/efficiency of the hat operator is disputed, it remains the standard way to manage memory in your case of Visual C++ .NET.