Re: warning: class 'xxx' has virtual functions but non-virtual destructor
Re: warning: class 'xxx' has virtual functions but non-virtual destructor
- Subject: Re: warning: class 'xxx' has virtual functions but non-virtual destructor
- From: Kevin Grant <email@hidden>
- Date: Mon, 5 Jan 2004 20:22:19 -0600
I'm getting this warning:
class 'xxx' has virtual functions but non-virtual destructor
This warning is correct, but what does it really mean? What are the
gotchas to having a class with virtual functions and a non-virtual
destructor?
Many people have given examples and reasons, but in essence a virtual
destructor, like all other virtual things, allows the "right code" to
run based on the runtime type of an object. It can be particularly
important when destroying objects because, for example, a subclass
might allocate gobs of memory that its superclass doesn't, and if you
ran only the superclass destructor the extra memory would definitely be
leaked.
[Of course, there are all kinds of places where you should use
"virtual", which is what makes the "final" keyword in Java so brilliant
by comparison, but I digress. :) ]
Kevin G.
http://homepage.mac.com/kmg/
mail to kevin at ieee dot org
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.