Can a constructor return a NULL value?

I agree with everyone else that you should use exceptions, but if you do really need to use NULL for some reason, make the constructor private and use a factory method:

static CMyClass* CMyClass::create();

This means you can’t construct instances normally though, and you can’t allocate them on the stack anymore, which is a pretty big downside.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)