Explicit initialization of struct/class members
Posted
by Zephon
on Stack Overflow
See other posts from Stack Overflow
or by Zephon
Published on 2010-06-09T06:40:32Z
Indexed on
2010/06/09
6:52 UTC
Read the original article
Hit count: 251
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 and is supported for compatibility with C programs, but this only compiles with C++, not with the C compiler. I'm using Visual C++ 2005.
In C this type of initialization
struct some_struct n = {0};
is correct and will zero-initialize all members of a structure.
Is the empty pair of braces form of initialization standard? I first saw this form of initialization in a WinAPI tutorial from msdn.
© Stack Overflow or respective owner