Rule Definition
Each constructor must initialize members defined with a scalar type or that are pointers in order to reduce the risk of an invalid state after successful construction and to ease the understanding of the code.
Not initializing scalar members and pointers can lead to unexpected behavior.
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
C++
Technical Criterion
CWE-665 - Improper Initialization
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.