Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of ^ variables in C++/CX

I've just returned to C++ for a game related project for Windows 8/RT after many years of absence in favor of C#.

Working with the generated Game Project Skeleton I've stumbled upon method signatures like the one below. Could anyone enlighten me what's the ^ is supposed to do?

Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
like image 798
Oliver Weichhold Avatar asked Nov 08 '12 10:11

Oliver Weichhold


People also ask

What do you mean by variable in C?

Variable is basically nothing but the name of a memory location that we use for storing data. We can change the value of a variable in C or any other language, and we can also reuse it multiple times.

What is variable in C example?

Variables are containers for storing data values. In C, there are different types of variables (defined with different keywords), for example: int - stores integers (whole numbers), without decimals, such as 123 or -123. float - stores floating point numbers, with decimals, such as 19.99 or -19.99.

Where declare variable C?

The convention in C is has generally been to declare all such local variables at the top of a function; this is different from the convention in C++ or Java, which encourage variables to be declared when they are first used.


2 Answers

In C++/CX, a T^ is a handle to a T object. It's effectively a smart pointer that owns a reference to the pointed-to object, with some extra bonus features provided by the compiler.

You can find out all about hats in the article, "Types That Wear Hats."

like image 165
James McNellis Avatar answered Oct 13 '22 04:10

James McNellis


Apparently it's called the handle-to-object operator.

The handle-to-object operator ^ is known as a "hat" and is fundamentally a C++ smart pointer. The memory it points to is automatically destroyed when the last hat goes out of scope or is explicitly set to nullptr.

According to: https://msdn.microsoft.com/en-us/library/hh699870.aspx. (From the "Memory Management" section of that page.

like image 45
Elliot Avatar answered Oct 13 '22 03:10

Elliot