Class members are initialized in the order in which they are declared in the class, not the order in which they appear in the class initializer list. To avoid errors caused by order-dependent initialization, the order of members in the initialization list should match the order in which members are declared in a class.


== Noncompliant Code Example

----
#include <iostream>

class C {
public:
  int x;
  int y;

  C(int i) : y(i), x(y + 1) { }  // Noncompliant
};

int main() {
  C c(1);
  std::cout << c.x << " " << c.y << std::endl;  // prints 1 1
}
----


== See

* https://wiki.sei.cmu.edu/confluence/x/dXw-BQ[CERT, OOP53-CPP.] - Write constructor member initializers in the canonical order
* https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#c47-define-and-initialize-member-variables-in-the-order-of-member-declaration[{cpp} Core Guidelines C.47] - Define and initialize member variables in the order of member declaration


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
