Do I need a default constructor?
Code:
class CObjects
{
public:
// default constructor
CObjects() : mesh(0) { }
CObjects(Mesh *m) { mesh = m; }
~CObjects() { }
};
I don't understand if I include the default constructor but calling the wrong constructor accidentally, the program will collapse. But it won't compile if I don't include the default one. Could anyone shed some lights on this?
Thanks
Jack
Re: Do I need a default constructor?
It depends on the way you want to use your class. e.g. if you want to add objects of your class into a standard container then it is needed.
Quote:
I include the default constructor but calling the wrong constructor accidentally, the program will collapse.
That has nothing to do with the existence of a default constructor. It must be a bug somewhere else. e.g. in your example the default constructor initializes ( the non existent ) member mesh to 0 but you're probably not checking for 0 somewhere else.
Kurt