I have below code:
class Base {
// Some code
Base(int y) {}
}
class Derived : Base {
int test;
Derived(int x);
}
Derived::Derived(int x) : Base(x) {
// Some code and calculation to generate vale of test
test = val;
}
I am compiling with flag '-Weffc++'.
And I get warning 'test need to be initialize in initialization list.'
But I can't do that as I need to do few calculation to generate value of test.
So to avoid this error I did try '-Wno-reorder' flag but it did not work. Also I don't prefer it, as it will disable this warning for all the code, I just want to disable this warning for this specific case.
I also did it using '#pragma GCC diagnostic ignore -Weffc++' placed just before constructor in cpp file and it did work. But I need to add pragma to all the constructors where I want to avoid this warning.
But is there any better way to avoid Weffc++ initialization list order warning for specific code. Or is there way to fix this warning?