I want to check to see whether something is null, e.g.:
string xxx(const NotMyClass& obj) {
if (obj == NULL) {
//...
}
}
But the compiler complains about this: there are 5 possible overloads of ==.
So I tried this:
if (obj == static_cast<NotMyClass>(NULL)) {
This crashes because NotMyClass‘s == overload doesn’t handle nulls.
edit: for everyone tell me it can’t be NULL, I’m certainly getting something NULL like in my debugger:

In a well-formed C++ program, references are never
NULL(more accurately, the address of an object to which you have a reference may never beNULL).So not only is the answer “no, there’s no way”, a corollary is “this makes no sense”.
Your statement regarding C makes no sense either, since C does not have references.
And as for Java, its “references” are more like C++ pointers in many ways, including this one.
Comparing such specific behaviours between different languages is something of a fool’s errand.
If you need this “optional object” behaviour, then you’re looking for pointers:
But consider whether you really need this; a decent alternative might be
boost::optionalif you really do.