Having a constructor does not make structnon-POD.
An aggregate class is called a POD if it does not have a custom copy assignment operator and destructor, and none of its non-static members is a POD class class, non-POD array, or reference.
Given that it’s completely safe to call
memset(&obj, 0, sizeof obj);
for an object structthat has a constructor if it is a POD.
Regardless of whether it is in order or not, it depends. If the default constructor structwants the member to be initialized to 1for normal behavior, the above call memsetmay affect the behavior of the code, which depends on 1, which is the default value.
Take an example of the following struct:
struct Direction
{
Direction() : x(1.0), y(0.0), z(0.0) {}
double x;
double y;
double z;
};
Direction , . , . memset 0, , , .
, POD ++ 03 ++ 11.
memset(&obj, 0, sizeof obj); .