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



On Jan 05, 2004, at 16:59, Kevin Hoyt wrote:

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?

Scott Meyers, Bjarne Stroustrup, et. al. have provided much better explanations in their various tomes, but simply, if you don't use a virtual destructor, you can't be sure that your base object gets properly destroyed. f or instance:


class a {};
class b : a {};

a* pa = new b;
delete a; // if a::~a isn't virtual, b::~b won't be called.


Suffice to say, you should always have a virtual destructor; and I believe that C++200x (i.e., the next version of the C++ standard) will specify this as a default.


--Matthew Peltzer
_______________________________________________
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: 
 >warning: class 'xxx' has virtual functions but non-virtual destructor (From: Kevin Hoyt <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.