Default initialization in C++

后端 未结 4 979
日久生厌
日久生厌 2020-12-04 19:54

I was asking myself something this morning, and I can\'t find the words to properly \"google\" for it:

Lets say I have:

struct Foo
{
  int bar;
};

s         


        
4条回答
  •  孤街浪徒
    2020-12-04 20:35

    Since bar is a built-in type its default initialization will be undefined for Foo1 and Foo2. If it would have been a custom type, then the default constructor would have been called, but here it's not the case.

    Lesson: always initialize your variables.

提交回复
热议问题