1

I'm currently working on a C++ application. I came across this operator: ^

In my case it's not the XOR I guess, because in the given code the usage is like that:

as a variable declaration:

Dictionary<System::String^, List<int>^>^ Tomatoes;

or as a Method returning parameter:

Food::Vegetable^ Vegetable_Create(List<KeyValuePair<int, Dictionary<System::String^, float>^>>^ a, List<KeyValuePair<System::String^, Food::Cucumber^>>^ b, Dictionary<System::String^, float>^ c);

I was wondering what the ^ operator is actually used for.

Do you know what the ^ operator is used for in C++ and is it really necessary?

Thanks!

Aconcagua
  • 24,880
  • 4
  • 34
  • 59
timhorton42
  • 241
  • 5
  • 15
  • 2
    Also possibly https://stackoverflow.com/questions/500580/in-c-cli-what-does-the-hat-character-do – Tas Dec 14 '18 at 11:08
  • @Tas I've voted to close this (500580) as dup of [this](https://stackoverflow.com/questions/202463/what-does-the-caret-mean-in-c-cli) (202463). Please help me ;) – YSC Dec 14 '18 at 11:13
  • 2
    It stands for a managed pointer in CLI. An abomination in other words. The first version of the CLI retained `*` and a `gc_new` family of functions to create managed objects. Why they didn't plump for a smart pointer class instead rather than fiddling around with language thereby risking compatibility breaks with future C++ standards is quite beyond me. – Bathsheba Dec 14 '18 at 11:14

1 Answers1

2

The ^ operator in C++/CLI denotes a managed pointer. So int* is a raw pointer to an integer, while System::String^ is a managed pointer to a CLI string.

All .Net classes must be handled via managed pointers or managed references (the % operator I think). So yes, it is absolutely necessary. It is, in fact, one of the most fundamental parts of C++/CLI. It is not part of normal C++.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157