Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: warning: class 'xxx' has virtual functions but non-virtual destructor



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.

References: 
 >Re: warning: class 'xxx' has virtual functions but non-virtual destructor (From: Clark Cox <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.