Deleting a virtual base class pointer gives segmentation fault.

Nathan Sidwell nathan@acm.org
Sun Oct 31 23:03:00 GMT 1999


Fredrik Vhrstrvm wrote:

> It is only the virtual desctructor that makes this possible. In my
> original code I have many virtual functions in Alfa, but no
> destructor since Alfa is only used as an interface class. I would
> like to avoid adding real code to an interface class and because of
> that I tried to following code:
> 
> struct Alfa
> {
>         virtual ~Alfa () = 0;
> };
> 
> It compiles, but fails at linking. Maybe a warning should be emitted
> for this code, or maybe not.....
When you make such an abstract class, you should still provide a definition
of the dtor, as derrived classes will need it. Making it abstract will
prevent a naked Alfa object. [class.dtor]/7

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk



More information about the Gcc-bugs mailing list