virtual destructor

Pages: 12
I wrote order of destruction and even quoted standard several times.
When B is destroyed:

1) B destructor body is executed. It is empty: do not do anything
2) Destructors for all B members are called. There is none, do nothing
3) Destructor for vector is called
3.1) vector destructor body is executed. It is empty: do not do anything
3.2) Destructors for all vector members are called. There is none, do nothing
Finish

If you delete it through pointer to base class (vector), due to non-virtual destructor compiler will assume that vector is the final type and only step 3 is executed, leavind first two incomplete. This is why it causes Undefined Behavior.
ok, thanks!!!....I see it clear...have you seen my post at 16:18???.
YOu are correct here. I cast it to reference because I felt like doing so, but you can even cast a pointer, and it would work as long as you will make it unambiguous: ptr = (Receiver*)&radio;
ok, It's an upcast that's why you didn't use a dynamic_cast, inst it?
Yes. With pointers it is better to use at static_cast, to avoid accidental reinterpret/const_cast whic c-style cast performs too.
I have read that you can just do dynamic_cast from pointer or reference which belongs to polymorphic classes. A polymorphic class is consider when it contains a virtual function...it doesn't have relation with base virtual class...
A polymorphic class is consider when it contains a virtual function...it doesn't have relation with base virtual class...
Yes. If you need downcast with dynamic_cast, you are better to have at least one virtual function.
ok, thanks
Topic archived. No new replies allowed.
Pages: 12