C++ Coding Standard Specification - CERN
C++ Coding Standard Specification - CERN
C++ Coding Standard Specification - CERN
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>C++</strong> <strong>Coding</strong> <strong>Standard</strong><br />
<strong>Specification</strong><br />
3 <strong>Coding</strong> Version/Issue: 1.1/5<br />
3.3.2 Constructor Initializer Lists<br />
CL6<br />
Initialise in the class constructors all data members.<br />
And if you add a new data member, don’t forget to update accordingly all constructors,<br />
operators and the destructor.<br />
CL7<br />
Let the order in the initializer list be the same as the order of declaration in the header file: first<br />
base classes, then data members.<br />
It is legal <strong>C++</strong> to list initializer in any order you wish, but you should list them in the same<br />
order as they will be called.<br />
The order in the initializer list is irrelevant to the execution order of the initializers. Putting<br />
initializers for data members and base classes in any order other than their actual<br />
initialization order is therefore highly confusing and can lead to errors. A data member could<br />
be accessed before it is initialized if the order in the initializer list is incorrect.<br />
Virtual base classes are always initialized first, then base classes, data members, and finally<br />
the constructor body for the most derived class is run.<br />
Example:<br />
class Derived : public Base { // Base is number 1<br />
public:<br />
explicit Derived(int i);<br />
Derived();<br />
};<br />
private:<br />
int jM; // jM is number 2<br />
Base bM; // bM is number 3<br />
Derived::Derived(int i) : Base(i), jM(i), bM(i) {<br />
// Recommended order 1 2 3<br />
}<br />
// Empty<br />
Source CXX-35, CXX-36<br />
Status Majority<br />
Not Common for CMS (will be OK in the future)<br />
page 18<br />
FINAL