Solved

C++/CLI -- what about NULL?

Posted on 2009-05-08
6
1,158 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:Daniel Wilson
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 400 total points
ID: 24341069
Isn't the managed code version of NULL nullptr (or maybe just null) in managed C++?
0
 
LVL 2

Assisted Solution

by:Gregdo
Gregdo earned 100 total points
ID: 24341103
Yes, the managed version of NULL is nullptr.
0
 
LVL 32

Author Comment

by:Daniel Wilson
ID: 24341111
nullptr did it.  Thanks!
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 40

Expert Comment

by:evilrix
ID: 24341128
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 :)
0
 
LVL 2

Expert Comment

by:Gregdo
ID: 24341161
Ah, yes, I recall reading that nullptr will be replacing NULL.  I wonder if this will force MS to make a change!
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24341190
>>  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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question