How can one branch of class tree have all its Zero initialized members be rubbish?

前端 未结 1 1930
星月不相逢
星月不相逢 2021-01-28 11:34

(not rubbish only if zero initialized as static scope member.) and it works as expected on GCC!(((

So for code like:

#include 
#include &         


        
相关标签:
1条回答
  • 2021-01-28 12:39

    It appears to be a compiler bug: according to this report members of base classes are not zero-initialised during value-initialisation of the derived class.

    As far as I can see, there is nothing wrong with your code, and all class members should be zero-initialised on a conforming C++03 or C++11 compiler.

    I guess your options are:

    • make the classes more POD-like by avoiding inheritance; or
    • add default constructors to any base classes to explicitly zero-initialise all members; or
    • use a less broken compiler.
    0 讨论(0)
提交回复
热议问题