Friday, April 14, 2017

Constructor initialization order

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

In this case the order should be a(2), b(1) because the order in which declared in the class is the same
or we can turn on -Wno-reorder

references
http://stackoverflow.com/questions/1564937/gcc-warning-will-be-initialized-after

No comments:

Post a Comment