Should constructor initialize all the data members of the class?

前端 未结 5 665
暗喜
暗喜 2021-02-02 13:48

I have a situation like this:

class A {
public:
  A() : n(0) {}
private:
  int n;
  int m;
}

There is simply no meaning in the application logi

5条回答
  •  抹茶落季
    2021-02-02 14:25

    For completeness, the warning comes from the C/C++ Code Analysis. In particular the problem is Potential Programming Problems / Class members should be properly initialized

    To change the code analysis settings (in this case I recommend per-project) edit the project properties. You can disable the whole warning, or disable it on just the files that violate the warning condition.

    As for comparing CDT with GCC or CLang, this appears to be a case where additional code analysis is being done by CDT compared to what is available from the compilers. Of course that is to be expected as the CDT Code Analysis' remit is greater than that of the compiler.

    PS, If you are up for it, you can read the implementation of this particular checker.

提交回复
热议问题