Hello
I want to know if it it safe to destroy an object using a pointer of its base class type, for example, would this free all memory?
in this case will the allocated memory be fully freed or will the delete only deallocate the memory that the base class occupies?Code:class a1 { public: int i; } class a2 : public a1 { public: int i2; } int main() { a1* aa2 = new a2; delete aa2; }
And also, as you probably can tell already, i don't really know how delete knows how much memory to dealocate, so if someone could explain it to me, or at least point me to an article that would explain it i would be very grateful.
Thanks for the attention.
Edit: Damn, just realized i posted this on the wrong board, can someone move this please?



LinkBack URL
About LinkBacks



