Explicit initialization of struct/class members

前端 未结 4 1989
清歌不尽
清歌不尽 2021-02-13 15:22
struct some_struct{
    int a;
};
some_struct n = {};

n.a will be 0 after this;

I know this braces form of initialization is inherited from C a

4条回答
  •  佛祖请我去吃肉
    2021-02-13 16:10

    It is standard in C++, it isn't in C.

    The syntax was introduced to C++, because some objects can't be initialized with 0, and there would be no generic way to perform value-initialization of arrays.

提交回复
热议问题