Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++/CLI -- what about NULL?

Posted on 2009-05-08
6
Medium Priority
?
1,194 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 1600 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 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

885 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