Default initialization in C++

后端 未结 4 968
日久生厌
日久生厌 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:42

    Case 3 is the proper way, with a member initialization list.

    None of the first two will be properly initialized, since you don't give them an initial value (exactly like a variable only defined is not initialized).

提交回复
热议问题