1 /*2 1. Members are initialized in the order in which they appear in the class, rather than in the order in which they appear in the initialization list!3 a good habit is to initialize in the order in which the members are defined. 4 2. Array members are incorrect in the initialization parameter list5 */6#include <iostream>7#include <cstdio>8#include <cstring>9#include <algorithm>Ten One using namespacestd; A - - structnode{ the intI, J; - intnum[ A]; - //node (int x): j (x), I (j) {}//wrong initialization. - /* + the value of I here is undefined because although J appears in the initialization list in front of I, but I is defined before J, I is initialized first, - while I was initialized by J, J was not initialized at this point, so the value of I was undefined and then the J was initialized. + */ A //node (): Num[1] (1), num[2] (3) {}//the wrong writing atNodeintx): I (x), J (i) {} - void out(){ -cout<<i<<" "<<j<<Endl; - } - }; - in intMain () { -Node A (4); toA. out(); + return 0; -}
Some questions about initializing parameter list in C + +