c++ - Can a constructor return a NULL value? -


I know the constructors do not "return" anything, but for example if i CMyClass * object = New CMyClass () Is there a way to create an object for the manufacturer to fail? In my case, I have some images which have to be loaded and if the file fails to read, I want to empty it. Is there any way to do this?
Thanks in advance.

I agree with everyone that you should use exceptions, but if you really have any reason To use NULL, make the constructor private and use a factory method:

  Fixed CMyClass * CMyClass :: create ();  

This means that you can not normally create examples, and you can not allocate them on the stack any longer, which is a big negative side.

< / Div>

Comments