gcc warning" 'will be initialized after'

前端 未结 7 800
走了就别回头了
走了就别回头了 2020-12-22 16:38

I am getting a lot of these warnings from 3rd party code that I cannot modify. Is there a way to disable this warning or at least disable it for certain areas (like #pragma

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-22 17:34

    Class C {
       int a;
       int b;
       C():b(1),a(2){} //warning, should be C():a(2),b(1)
    }
    

    the order is important because if a is initialized before b , and a is depend on b. undefined behavior will appear.

提交回复
热议问题