I often come across POD structures in code that are manually initialized using memset as follows:
struct foo; memset(&foo, 0, sizeof(foo));
I checked the C ++ 11 standard and it says: "An object whose initializer is an empty set of brackets, i.e. (), must be initialized with a value." Further: "To initialize a [pod struct] value of type T means ... the object is initialized to zero."
So ... this means that you can always safely condense the above code only as follows:
struct foo{};
And have a guaranteed initialized structure, as if you called memset(&foo, 0, ...) ?
If this is the case , then, generally speaking, you can safely initialize something with empty initializers:
SomeUnknownType foo{}; // will 'foo' be completely "set" to known values?
I know that this was not always possible in C ++ 03 (until the equivalent initialization syntax ), but is it now possible in C ++ 11 for any type?
c ++ c ++ 11 uniform-initialization
Miketusar
source share