I want to zero out all members of a derived structure.
There are hundreds of members and more are added every once in a while so I feel that initializing them explicitly is error-prone.
The structures have no virtual functions and all the member fields are built-in. However, they are not POD by virtue of having non-trivial constructors.
Apart from the standard frowning on the practice, do you see any issues with the following?
struct Base
{
// Stuff
};
struct Derived : public Base
{
// Hundreds of fields of different built-in types
// including arrays
Derived()
{
::memset(reinterpret_cast<char*>this + sizeof (Base), 0, sizeof *this - sizeof (Base));
}
};
Thanks.
memset
is definitely not the solution to this problem. – Giffy