I'm working on some kind of smart pointer technique but there is one piece I'm missing. I tried several combinations but the logic is as follow:
UInt *obj = new UInt;
UInt *ref;
ref = obj;
delete obj;
obj = NULL;
if (ref == NULL)
{
// It works
}
else
{
// It failed
}
Is there any way to hit "It Works" without setting ref to NULL explicitly?
EDIT:
A more appropriate scenario would be something like this:
class A
{
public:
A(): ref(NULL) {}
~A()
{
if (ref != NULL)
delete ref;
}
int *ref;
};
int *obj = new int;
A *host = new A();
host->ref = obj; ???
delete obj;
obj = NULL;
if (host->ref == NULL)
{
// It works.
}
else
{
// It failed.
}
...
Can't use int*& ref as a class member though.... must be close.