Re: [sigc] sigc::trackable::~trackable() is not virtual



On Thu, 2006-10-26 at 20:36 +0200, stephan beal wrote:
> IMO, any change which fixes undefined behaviour should be made 
> regardless of any perceived performance hit.

If you can submit a test case I will consider it. I don't think there is
any bug, so you have to show that it exists.

> Whether it's undefined only when i delete using a parent pointer or a 
> child pointer is irrelevant. Opening the door to undefined behaviour 
> leads to undefined behaviour. The door shouldn't even be open.

C++ does not protect you from errors. You must know what you are doing.

Likewise, you can provide an incorrect reference to a std::list<>, and
it will cause a crash (or "undefined behaviour"). 

[snip]
> i'm not so optimistic about that point. The moment someone does use a 
> trackable like that, they've got undefined behaviour and probably won't 
> know why.

They must know why. This is very basic C++.

"Meant to be subclassed" does not mean "meant to be used
polymorphically". I've made that point repeatedly now.

[snip]
> - Classes not designed to be base classes or not designed to be used 
> polymorphically should not declare virtual destructors.
[snip]

> struct foo : public trackable { ... };
> 
> trackable * t = new foo;
> 
> This is already polymorphism, regardless of any function calls.

So, don't do that.

>  A dtor 
> is a function call, too, so i will argue that any public subclassing is 
> automatic polymorphic behaviour.

That's quite clearly wrong. C++ is not as simple as you'd like it to be.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]