I'm currently starting a new project to just mess about with inheritance and polymorphism (something I've not even looked at for a good 10 years), and I'd like my code to use the new nullptr keyword.
The problem I have is that my compiler doesn't actually support it yet, so as a hack I've, defined it as a const int, like so:
const int nullptr = 0;
...for the time being.This has left me curious as to whether my code will be broken when I do get a compiler that supports nullptr - will nullptr implicity convert to 'false'?
Perhaps it's best with an example. Say I had a pointer to an object, which may contain nullptr or may contain a valid address. Would the following snippet still work?
if (pObject)
{
pObject->someFunction();
// and other stuff
}
else
{
pObject = new Object;
// and other stuff
}
Simlarly, if I had a vector of pointers, some of which are set to nullptr, could I still use this to delete the objects in a class destructor?
for (unsigned int i = 0; i < pObjects.size(); ++i) if (pObject) delete pObject;
Many thanks,
Ronnie