On Fri, 4 Mar 2005, Jonathan Wakely wrote:

> On Fri, Mar 04, 2005 at 03:51:42PM +0100, Karel Gardas wrote:
>
> > I would like to ask if the behaviour of GCC 4.0.0 20050301 is correct or
> > not. I have for example abstract base class like:
> >
> > class Foo
> > {
> > public:
> >     virtual unsigned short
> >     iiop_version() const = 0;
> > };
> >
> > and when I compile it, GCC emits warning from subject, although this class
> > is really abstract and will never be instantiated. It's quite easy to add
> > virtual dtor there, but I'm reluctant to do so, since IMHO GCC should
> > check if the class is abstract or not, so I would like to ask if I should
> > fill a bugreport or correct my code.
>
> If it's an Abstract Base Class and you intend to use it through a
> pointer-to-base (or reference-to-base) then it's important that you add
> a virtual dtor.
>
> Whether it is abstract or not has nothing to do with it - if you will
> ever delete a derived object with a static type of the base class then
> the behaviour is undefined if the base class does not have a virtual
> dtor.
>
> e.g. this is undefined behaviour:
>
> class Base {};
> class Derived : public Base {};
>
> Base* p = new Derived;
> delete p;

Yes, that's undefined, but I just define this class to be able to do:

Foo* f = dynamic_cast<Foo*>(x);
l = f->iiop_version();

there is nothing like delete involved. Anyway, I agree with you that emit
warning about this is probably the right thing to do and so I will fix my
code.

Thanks,
Karel
--
Karel Gardas                  [EMAIL PROTECTED]
ObjectSecurity Ltd.           http://www.objectsecurity.com

Reply via email to