PRB: Error Message When You Try to Locate a NULL Pointer in Managed Extensions for C++ (310919)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition

This article was previously published under Q310919

SYMPTOMS

In a Managed Extensions for C++ project, when you try to locate a null pointer by using the following code:
System::Object* ptrObject;
if(ptrObject != NULL)
{
   ...
}
				
you may receive the following error message:
"error C2065: 'NULL' : undeclared identifier"

CAUSE

The null value is a macro that is defined in the C/C++ header files. Those header files are not included in Managed Extensions for C++ projects.

RESOLUTION

Use zero (0), instead of null, as in standard C++. The code resembles the following sample code:
System::Object* ptrObject;
if(ptrObject != 0)
{
   ...
}
				

STATUS

This behavior is by design.

Modification Type:MajorLast Reviewed:5/21/2002
Keywords:kbprb KB310919