bigbaz34
bigbaz34

Reputation: 395

Compiler error C2440

I am getting error c2440 in my compiler but I cannot figure out what is causing it.

This is the error:

Error 2 error C2440: 'initializing' : cannot convert from 'int' to 'System::String ^'   c:\users\***.****\documents\visual studio 2005\projects\cpas1\cpas1\Form1.h 1083

and this is the relevant code:

String *strFilename = 0;

Upvotes: 4

Views: 1145

Answers (3)

C.J.
C.J.

Reputation: 16081

Managed types, when used in Managed C++, don't use stars (i.e. *), instead I believe they are called tracking handles (i.e. ^). As such your statement should be written like this:

String^ strFilename = nullptr;

Upvotes: 4

Puppy
Puppy

Reputation: 146910

System::String is a managed class. You must use nullptr keyword, I believe, to initialize it.

Upvotes: 2

Kinexus
Kinexus

Reputation: 12904

String *strFilename = "0";

not

String *strFilename = 0; 

Upvotes: 2

Related Questions