Does a c++ struct have a default constructor?

前端 未结 5 1536
野趣味
野趣味 2020-11-28 08:51

I wrote the following code snippet:

void foo()
{
    struct _bar_ 
    {
        int a;
    } bar; 

    cout << \"Value of a is \" << bar.a;
}
<         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 09:13

    Member variables of a struct are not initialized by default. Just like a class (because a struct is exactly the same thing as a class, only in struct the members are public by default).

提交回复
热议问题