Rule Definition
All data member from a class must be initialized in each constructor of this class to avoid undefined behavior after successful construction and to simplify the understanding of the code.
Remediation
Initialize scalar-typed members in constructor header.
Violation Code Sample
class C
{
public:
C() { }; // VIOLATION: m_i is not initialized
protected:
int m_i;
}
Fixed Code Sample
// Remediation
class C
{
public:
C() : m_i(0) { }
protected:
int m_i;
}
Reference
Effective C++, Item 12
Industrial Strength C++ 5.5
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.