Why do I get “warning: missing initializer for member”? [-Wmissing-field-initializers]

后端 未结 5 2109
名媛妹妹
名媛妹妹 2021-01-04 20:14

I\'m wondering why I am getting a warning about initialization in one case, but not the other. The code is in a C++ source file, and using GCC 4.7 with -std=c++11

5条回答
  •  一个人的身影
    2021-01-04 20:53

    Here is a simple example:

    #include 
    
    struct S {
      int a;
      int b;
    };
    
    int main() {
      S s { 1 }; // b will be automatically set to 0
                 // and that's probably(?) not what you want
      std::cout<<"s.a = "<
                                                            
提交回复
热议问题