Meaning of ^ variables in C++/CX [duplicate]
Asked Answered
S

3

7

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)
Selfconceit answered 8/11, 2012 at 10:2 Comment(3)
That's C++/CX. It's a WinRT handle.Modifier
@R.MartinhoFernandes Thanks. Migrate your comment to an answer, and I'll mark it resolved.Selfconceit
@Alex, billz: no, it's not a duplicate. C++/CX is different from C++/CLI, even if they share syntactic elements. Please don't be fooled by syntax. Oliver: I am not sure if I got the exact terminology, or all the details about exactly what it does, so I just dropped a comment so you have something you can google. I'll leave writing a proper answer for someone that really knows.Modifier
C
7

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."

Cassycast answered 8/11, 2012 at 16:48 Comment(0)
R
1

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.

Residential answered 16/3, 2015 at 10:41 Comment(0)
S
-1

The ^ symbol is a handle to an object.

For example String^ s; declares a handle to a 'String' object.

http://en.wikipedia.org/wiki/C%2B%2B/CLI#Handles

Sightless answered 8/11, 2012 at 10:18 Comment(7)
And a link to C++/CLI - Nrgh. It's C++/CX, which is a totally different language. Don't be fooled by the wrong closing reason of this question.Severance
I'm now fascinated as to why this merited so many downvotes without any explanation as to why. The caret token has the same meaning in both /CLI and /CX, no?Nacelle
@Rook: does it? (AFAIK in one language it means "managed CLR handle", in the other it means "ref-counted WinRT handle"; those sound different to me). If it means the same put that in an answer. (this one does not do so.)Modifier
@R.MartinhoFernandes thankyou for clearing that up. If an answer is incorrect, simply downvoting without explaining why it is wrong is pretty unhelpful, wouldn't you say?Nacelle
@Nacelle Well, I for myself gave an explanation of why it is wrong in my comment, which is "the answer refers to a totally different language where this symbol naturally has a totally different meaning". And for the others I could only guess they didn't have another explanation to add (which isn't neccessary anyway).Severance
@ChristianRau there were 2 downvotes before you commented. And yes, it isn't necessary to explain a downvote, but if the answer isn't clearly stupid and wrong, a downvote without explanation provides almost no information of worth or value, so who does it benefit?Nacelle
@Nacelle Ah sorry, didn't remember there were already downvotes without comments. They probably relied on the comments to the question for an explanation. But you're right in that they could have given a reason, especially when it's that straight forward.Severance

© 2022 - 2024 — McMap. All rights reserved.