what does this symbol ' ^ ' represent in C++

Oct 7, 2014 at 5:52pm
Hi everyone. I recently came across C++ code that use this ^to declare variables. Please see example code below.
1
2
3
private: System::Windows::Forms::Button^  Button1000;
	private: System::Windows::Forms::Label^  ChannelLabel;
	private: System::Windows::Forms::Button^  ButtonDisable;


I don't know what this symbol represents. Could it be some kind of a special pointer maybe. If anybody knows what it represents please share your knowledge.
Oct 7, 2014 at 5:57pm
The code you're looking at is C++/CLI instead of native C++. C++/CLI is a Microsoft language meant to provide interop between the native C++ world and the managed world of .NET. The syntax here indicates .NET managed references, which are subject to garbage collection by the .NET Runtime's memory management system. On regular C++ pointers you'd have to delete them yourself or use RAII techniques to release acquired resources appropriately. These managed references do not require this.

The way they are allocated is different, as well. Managed resources use gcnew instead of new.
Oct 7, 2014 at 5:57pm
closed account (z05DSL3A)
That is C++/CLI not C++ and it's a "handle" and is kind of like a cross between a pointer and a reference.
Oct 7, 2014 at 6:49pm
Thank you guys. One last question; I am suppose to expand this code with new features. Can I do this with pure C++ or must I learn C++/CLI to add these features.
Oct 7, 2014 at 7:12pm
It depends on what features you're trying to expand. If you are making modifications to the GUI, you should probably be more familiar with C++/CLI. The types you presented in the original post come from a Microsoft-specific UI toolkit called Windows Forms. These libraries are all .NET libraries, which is why the C++/CLI syntax is needed. If your GUI is not changing, and you are only altering some background calculations in code that seem to be pure C++, you can probably get by on your pure C++ coding ability.
Oct 10, 2014 at 2:21am
closed account (1CfG1hU5)
older c languages, '^' is an exclusive or operator, in the newer languages i believe
is used for pointers. someone please post if I am incorrect about the pointer.
Oct 10, 2014 at 6:56am
I think it's reference to managed object in C++/CLI.
I have to say this language is a monster!
Oct 10, 2014 at 8:13am

someone please post if I am incorrect about the pointer.

You are correct when you say ^ is the bitwise exclusive OR operator, but you are incorrect in saying it is being used here.
Oct 10, 2014 at 8:26am
In C++ ^ is a bitwise xor. In C++/CLI it is both a bitwise xor and managed handle.
Oct 10, 2014 at 8:52am
closed account (1CfG1hU5)
saw ^ being used with strings somewhere. i'll look online for a reference maybe later.

incorrect in saying being used here? you're saying that ^ isn't used here?
or do you mean that not used here for use with strings?

looking for a more specific response
Oct 10, 2014 at 10:03am
I was just saying it is not being used as an xor operator in this context.
Oct 10, 2014 at 12:24pm
Operators (such as ^) can have different meanings in different contexts.
Using it in the OPs context it's a 'managed' pointer.
Topic archived. No new replies allowed.