In C++, how do I test if a pointer has been initialized? These don't run, as expected. How do I test? Here is the code:
TCHAR *sNullString;
INT bInitialized;
if (*sNullString)
bInitialized = TRUE;
if (sNullString)
bInitialized = TRUE;
In C++, how do I test if a pointer has been initialized? These don't run, as expected. How do I test? Here is the code:
TCHAR *sNullString;
INT bInitialized;
if (*sNullString)
bInitialized = TRUE;
if (sNullString)
bInitialized = TRUE;
In C++, how do I test if a pointer has been initialized?
In C++, it is not possible to test if a variable (of pointer type, or otherwise) has been initialized. Same applies to dynamically allocated objects.
How do I test?
You don't, because you can't. Instead, you write your code so that you can prove without a doubt that the pointer is initialized. An example:
TCHAR *sNullString = nullptr;
Here, there is no doubt: sNullString
is initialized, and it points to null.