You always should define default constructor for your class. You must also define a copy constructor for your class if there are any pointers in the class.
While it is not mandatory, failure to provide a default constructor can result in bad behavior, and failure to provide a copy constructor when you have pointers in the class will result in bad behavior.
For example, without a default constructor, the compiler will not fully initialize the attributes of the class. It will initialize the virtual function table, and call base class constructors, but that is all - the attributes could be random garbage.
For another example, without a copy constructor, the compiler will generate one that simply makes a bit wise copy of the attributes. If these attributes contain pointers, then you have two pointers to the same object, not necessarily a good thing, especially if one of them get "deleted".
Copyright © 2026 eLLeNow.com All Rights Reserved.