Why must initializer list order match member declaration order?

后端 未结 3 1178
[愿得一人]
[愿得一人] 2020-12-03 20:46

Why does gcc throw a hissy fit if the initializer list order doesn\'t match variable order in the class?

class myClass
{
public:
   int A;
   int B;
   myCla         


        
3条回答
  •  無奈伤痛
    2020-12-03 21:34

    The order of the initializer list does NOT matter. The declaration of your members in the class header defines the initialization order.

    This is by design and required as you could have multiple ctors having totally different init list orders.

    So your members will ALWAYS be initialized in the order of declaration.

提交回复
热议问题