Member not zeroed, a clang++ bug?

前端 未结 4 1346
孤街浪徒
孤街浪徒 2020-12-15 08:36

Consider the following code:

class A {
public:
    int i;
    A() {}
};

class B {
public:
    A a;
    int i;
};

int main() {
    B* p = new B {};
    std:         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 09:06

    Integral types are not required to be initialized to a value like that in a non-default constructor (since you have provided a constructor)

    Change your constructor to A() : i(0) {}.

提交回复
热议问题