Link to home
Start Free TrialLog in
Avatar of Daniel Wilson
Daniel WilsonFlag for United States of America

asked on

C++/CLI -- what about NULL?

Some of the code I'm upgrading to C++/CLI (.Net 2+) from Managed Extensions for C++ (.Net 1.1) compares an object to NULL or 0 to determine whether it's a null pointer.

But I'm getting a compile error on these lines.  
Cannot convert from 'int' to 'System::Drawing::Bitmap^'

Below is one of the functions in which I use the technique and get the error ... about 3 spots in this one.

What is the C++/CLI way to do this?

Thanks!
Bitmap ^ MyClass::LoadBMP(String ^fileName) {
 
		if(fileName == NULL || fileName == String::Empty) {                  // Make Sure A Filename Was Given
			return NULL;                                                    // If Not Return Null
		}
 
		// Make Sure The File Exists In One Of The Usual Directories
		if(!File::Exists(fileName)) {
			return NULL;                                                    // If Not Return Null
		}
 
		if(File::Exists(fileName)) {                                         // Does The File Exist Here?
			return gcnew Bitmap(fileName);                                    // Load The Bitmap
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniel Wilson

ASKER

nullptr did it.  Thanks!
Thanks Gredo, I couldn't remember if it was null or nullptr. The problem is that microsoft have screwed up a bit here because as from C++0X nullptr will be the unmanaged C++ null pointer type :)
Ah, yes, I recall reading that nullptr will be replacing NULL.  I wonder if this will force MS to make a change!
>>  I wonder if this will force MS to make a change!
I hope so

http://en.wikipedia.org/wiki/C%2B%2B0x#Null_pointer_constant