Am 05.05.2014 08:04 schrieb "Sven Barth" <pascaldra...@googlemail.com>:
>
> Am 05.05.2014 04:13 schrieb "Xiangrong Fang" <xrf...@gmail.com>:
> >
> > 2) What is the purpose of making destructor of TObject virtual?
>
> The destructor needs to virtual so that the correct one is called no
matter what static type a variable has. Imagine you have a TFoo which
inherits from TObject and you'd not have a virtual destructor, but only a
non-virtual one in both classes. Now if you call Free it would always be
TObject.Destroy that is called and not TFoo.Destroy, because Free is
declared in TObject and has no way if knowing that there is a TRio
descendant that has a constructor as well. And here virtual methods cone to
the rescue...

Of course that should have been TFoo at the end, not TRio... Stupid auto
completion -.-

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to