On Jan 05, 2004, at 18: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?
Not having a virtual destructor can break polymorphism. Take the
following example:
class A
{
public:
A() {}
~A() {}
};
class B
{
public:
B() {}
~B() {}
};
int main()
{
A *a = new B;
delete a; //B's destructor will never get called, because it (and A's
) are not virtual
}
As a general rule, any class that you intend to use polymorphically
(i.e. overload, and use virtual functions) should have a virtual
destructor as well.
--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.