Topic: non-virtual inheritance


Author: d96-mst@nada.kth.se (Mikael St ldal)
Date: 1997/01/20
Raw View
In article <vw9n2ue9k39.fsf@haggard.gg.caltech.edu>,
presto@haggard.gg.caltech.edu (Preston Pfarner) wrote:
>Why are these useful?  One important reason for (3) is that it
>prevents problems with destructors.  If one can prevent inheritance
>from class A, then A can have a non-virtual destructor.  This can be
>important for small classes, particularly to avoid the overhead of a
>vtable pointer.  In fact, many programmers choose to use non-virtual
>destructors, trusting that no one will derive any children.  This
>method seems risky, especially for long-term, maintainable code.

It would be even better if there was a way to allow safe non-virtual
inheritance. With that I mean that the compiler generates errors for
everything that will mess things up without polymorphism, I think it
could be as easy as disallow conversion from DerivedClass* to
BaseClass* for a particular BaseClass.


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]