Consider following sample code:
class C
{
public:
int* x;
};
void f()
{
C* c = static_cast(malloc(sizeof(C)));
c->x = nullptr; // &
This particular code is fine, because C
is a POD. As long as C
is a POD, it can be initialized that way as well.
Your code is equivalent to this:
struct C
{
int *x;
};
C* c = (C*)malloc(sizeof(C));
c->x = NULL;
Does it not look like familiar? It is all good. There is no problem with this code.