Is it possible to prevent omission of aggregate initialization members?

前端 未结 5 1929
孤城傲影
孤城傲影 2021-02-05 00:24

I have a struct with many members of the same type, like this

struct VariablePointers {
   VariablePtr active;
   VariablePtr wasactive;
   VariablePtr filename;         


        
5条回答
  •  有刺的猬
    2021-02-05 00:51

    For CppCoreCheck there's a rule for checking exactly that, if all members have been initialized and that can be turned from warning into an error - that is usually program-wide of course.

    Update:

    The rule you want to check is part of typesafety Type.6:

    Type.6: Always initialize a member variable: always initialize, possibly using default constructors or default member initializers.

提交回复
热议问题