Hi,
I wanted to use (x->isNull()) to find out, if I can safely use a pointer to something. However, if I use it like this:
SomeType *x;
//doing some work, perhaps giving x a new object to point to, perhaps not
if (x->isNull()) return false;
SomeType *x;
//doing some work, perhaps giving x a new object to point to, perhaps not
if (x->isNull()) return false;
To copy to clipboard, switch view to plain text mode
the program crashes on the if-condition. I can see why: there is no object to get the ->isNull() method from.
If I use:
if (x==0) return false;
if (x==0) return false;
To copy to clipboard, switch view to plain text mode
instead, it works.
Now I have three curious questions:
- Is it "legal" (aka: advisable) to use the second approach?
- Will *-Declarations ensure that the Variable points to 0 before it gets an object to point to?
- Is there any use for ->isNull()?
Bookmarks