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

后端 未结 5 2061
名媛妹妹
名媛妹妹 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:44

    That's a defective warning. You did initialize all the members, you just didn't have the initializers for each member separately appear in the code.

    Just ignore that warning, if you know what you are doing. I regularly get such warnings too, and I'm upset regularly. But there's nothing I can do about it but to ignore it.

    Why is the uninitialized struct not giving a warning? I don't know, but most probably that is because you didn't try to initialize anything. So GCC has no reason to believe that you made a mistake in doing the initialization.

提交回复
热议问题