deW1
deW1

Reputation: 5660

What does ^ mean in C++?

So I've just stumbled over this function in the WinApi

public:
static array<Process^>^ GetProcessesByName(
    String^ processName
)

What do the ^ stand for? Seems odd never seen this before.

Upvotes: 1

Views: 226

Answers (2)

Dimitrios Bouzas
Dimitrios Bouzas

Reputation: 42909

As already answered, in your example ^ stands for Microsoft's C++/CLI garbage controlled pointers.

However, in standard C++ ^ is the bitwise exclusive OR operator^.

operator^compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

#include <iostream>

int main() {
  int a = 0x5555;
  int b = 0xFFFF;
  std::cout  << std::hex << ( a ^ b ) << std::endl;
}

Live Demo

Upvotes: 0

crashmstr
crashmstr

Reputation: 28573

This is C++/CLI, and ^ is for references (which are allocated with gcnew). References are garbage collected.

.NET Programming in Visual C++

In this specific example, the function takes a reference to a string, and returns a reference to an array of references to Process. For anything that is a reference type, you must use ^ (in other words, you can't have a non-reference variable of that type).

As pointed out in a comment, this may instead be C++/CX, but the syntax is mostly the same, but uses ref new instead of gcnew.

Visual C++ Language Reference (C++/CX)

Upvotes: 2

Related Questions