如何创建一个在失败时创建空对象的构造函数 (c++)。
我想创建一个行为类似于DCMTKDicomImage
库中的类的类。
#include "diregist.h" /* required to support color images */
DicomImage *image = new DicomImage("test.dcm");
if (image != NULL)
{
if (image->getStatus() == EIS_Normal)
{
Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits per sample */));
if (pixelData != NULL)
{
/* do something useful with the pixel data */
}
}
else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;