Middle
In what order are list elements initialized in the constructor after the colon?
sobes.tech AI
Answer from AI
In the order of their declaration in the class, not in the order of their appearance in the constructor's initializer list.
Example:
class MyClass {
public:
int b;
int a;
MyClass() : a(1), b(2) {
// The element 'b' will be initialized first,
// because it is declared first in the class,
// despite the order in the initializer list.
}
};