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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class a1 {
public:
int i;
}
class a2 : public a1 {
public:
int i2;
}
int main() {
a1* aa2 = new a2;
delete aa2;
}
in this case will the allocated memory be fully freed or will the delete only deallocate the memory that the base class occupies?
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.