If undeclared/unimplemented, C++ will create default base constructor (no arguments), copy constructor, destructor, and assignment operator. The base constructor will do no initialization of variables whatsoever. The copy constructor will do a bit-wise copy of the copied data (member variables), as will the assignment operator. Often these are not safe. In any case, you should always create your own default constructor, and initialize all member variables. Example:
class foo
{
private:
int a;
int b;
int c;
public:
foo() : a(0), b(0), c(-1) {}
};
rubberman
Posting Maven
2,572 posts since Mar 2010
Reputation Points: 365
Solved Threads: 306
Skill Endorsements: 52
vijayan121
Posting Virtuoso
1,740 posts since Dec 2006
Reputation Points: 1,236
Solved Threads: 320
Skill Endorsements: 11
Question Answered as of 8 Months Ago by
vijayan121
and
rubberman