
AMDG
Patrick Horgan wrote:
Steven Watanabe wrote:
FWIW, non-virtual destructors are the norm in Boost. I strongly dislike the idea of having a policy enabling virtual destructors. Steven, could you tell me the reason for this?
There aren't a lot of virtual function in Boost either. A quick grep in trunk shows about 1200 virtual methods including 136 virtual destructors under boost. In ggl, the only virtual functions I see are in exception classes.
I have always thought that if you had virtual methods, you should have a virtual destructor since the derived class has something different about it and if being destructed via a reference or pointer to base, the wrong thing could happen without a virtual destructor! Educate me please. I've never heard of any reason to avoid a virtual destructor if you already had virtual methods. Obviously I'm missing something about something I thought I understood.
I don't think so. If you're using virtual functions in the normal OO way, a virtual destructor almost always makes sense. (The use of virtual in Boost.Exception is somewhat different. virtual is being used as an implementation detail to separate a fragment of the interface of a concrete type from the rest of the type in order to minimize dependencies. It isn't being used for polymorphism at all) But there are virtual destructors in exception of course (isn't exception pretty, elegant code btw?) I'm still a bit confused. Are you saying that destroying from a base class reference can't be a
Steven Watanabe wrote: problem? Of course that's true if the derived class doesn't ever add any extra dynamic value or system state, but even in that case, surely you'd want to have the virtual destructor anyway if there is a need for virtual functions, so that if someone less thoughtful was extending/maintaining it later, the design would keep those sorts of mistakes from being made. It's defensive programming. But what I was really asking about, was when you said:
Steven Watanabe wrote:
FWIW, non-virtual destructors are the norm in Boost. I strongly dislike the idea of having a policy enabling virtual destructors. It seems there's lots of virtual destructors in Boost, and you haven't told me why you are against them. In what way are they bad? In this statement you seem to come out against them quite strongly. You seem to be saying that you want it to be a rule that they are not to be used. Am I mis-reading this somehow?
Thanks, Patrick