...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <cstring>
struct S {
int i, j, k;
// ...
virtual void f();
};
void f() {
S *s = new S;
// ...
std::memset(s, 0, sizeof(S));
// ...
s->f(); // undefined behavior
} |
Compliant Solution
In this compliant solution, the data members of S
are cleared explicitly instead of calling std::memset()
:
...