Search code examples
.netpointersc++-clihandle

C++ only using ^ instead of *?


I read that for example

MyClass<T> ^ mc = new MyClass<T>();

gives a handle of mc.

  1. Can I use ^mc the same way I use *mc?

I also read, that using ^mc will create the object in the cli-heap that will automatically cleaned up, so I don't have to use delete mc then.

Wouldn't that be an argument to only use ^-handles ?


Solution

  • ^ pointers are only used in the Microsoft Common Language Runtime modification of of the language. If you use them, you are locking your project to use only the Microsoft compiler. If you're looking for portability, you should use traditional pointers that must be manually deleted or using the new C++11 features.