I see a lot of C++ libraries dealing with dynamic memory allocation this way:
Qimage* _image = new QImage(width, height, QImage::Format_RGB888);
if (!_image)
{
// Failed!
}
I find it interesting that it is possible to check whether an object was succesfully allocated or not with a simple code like if (!_image)
.
1) I wonder if this is a native feature of the standard new
or if this is only possible if you overload operator new
with your own implementation.
2) How would I go about implementing operator new
in this case, where it receives arguments for the object's constructor and it returns NULL in case width && height are 0?
Did I get any of this right?