Search code examples
c++syntaxc++-cli

^ after data type in Visual C++


What does ^ mean near the c++ data type?

enter image description here

This seems to only work in visual studio C++ and is clearly not a standard C++ syntax, so what does it do here? I am familiar with pointer * and reference &, but to see ^ after the data type, I have no clue.


Solution

  • In C++/CLI and C++/CX, ^ is the Handle to Object Operator:

    The handle declarator (^, pronounced "hat"), modifies the type specifier to mean that the declared object should be automatically deleted when the system determines that the object is no longer accessible.

    ...

    Because native C++ pointers (*) and references (&) are not managed references, the garbage collector cannot automatically update the addresses they point to. To solve this problem, use the handle declarator to specify a variable that the garbage collector is aware of and can update automatically.