Usage of the ^

MSDN frequently employs this syntax:

String^ path = "c:\\temp\\MyTest.txt";

My question regards the purpose of this syntax, as it is new to me.
Information regarding this topic would be most helpful. (i.e. is it an example of a bitwise operator, an assignment related operator, or even - though unlikely - an exponential operator.)
Thank you.
Wait... is MSDN now trying to pass off C++/CLI as C++? O_o

Explanation: This isn't C++. In C++/CLI, Microsoft added the type^ syntax for creating garbage-collected pointers, named handles. In addition, they added gcnew to be used with handles in place of new.

-Albatross
Last edited on
That is very interesting. I will have to familiarize myself with CLI. Thank you for the information. The way by which I came across this was in exploring the various ways and means of File IO. The example of using the System::File class employed several garbage-collected pointers. I was required to enable Common Language Support to use it, along with
1
2
3
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;

which makes sense now.

The interesting thing about going that route:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
				System::File srcFile;
				
				if(!File::Exists("Test.txt"))
				{
					StreamWriter^ srcSW = File::CreateText("Test.txt");
					try
					{
						srcSW->WriteLine("Type in lines of text");
					}
					finally
					{
						if(srcSW)
							delete (IDisposable^)(srcSW);
					}
				}
is that I get these errors:
1
2
3
4
error C2039: 'File' : is not a member of 'System'
error C3622: 'System::IO::File': a class declared as 'abstract' cannot be instantiated
c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::IO::File'
error C2512: 'System::IO::File' : no appropriate default constructor available


Do you have any input on the subject?

p.s. - I've also already added a reference to System in the project.
Last edited on
To get those errors to go away, all you have to do is get rid of this line:

System::File srcFile;

As the errors suggest, there is no "File" class in the System namespace. File is in the System::IO namespace. Also, System::IO::File is an abstract class (i.e. you cannot instantiate it. That is, you can't have a variable of type System::IO::File). It just has a bunch of static methods for creating FileStream objects (says MSDN).
Topic archived. No new replies allowed.