Solved

C++/CLI -- what about NULL?

Posted on 2009-05-08
6
1,142 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now