The compiler will translate a call to a member function into a call to a static function, with an implied this
parameter pointing to the object. That means the contents of the object, valid or invalid, are not relevant to the whether the call is made.
This changes if the method is virtual, since the vtable pointer must be valid. The constructor will initialize the vtable pointer. malloc
does not call the constructor, it doesn’t even know what a constructor is – it’s leftover baggage from C.
Note that this is not specified by the standard, but is how things are typically implemented.
8
solved Does malloc create a new instance of the class or not? [duplicate]