[LC++]Pure Virtual Functions and Derived Classes

Jack Lloyd lloyd at acm.jhu.edu
Thu May 2 05:10:06 UTC 2002


On Tue, 30 Apr 2002, Shaul Karl wrote:

> >
> > > Also, you may not create an instance of a firtual base class.
> >
> > Be careful with a statement like that. "virtual base class" means something
> > very different from "a base class with (pure) virtual functions"
> > (specifically, deriving using virtual inheritence).
> >
> > -Jack
> >
>
>
> What do you mean by `virtual inheritance'?

It's how you get around the so-called "diamond inheritance problem" in C++.
For example:

class A {};
class B : public A {};
class C : public A {};
class D : public B, C {};

The problem here is that D will have two base classes that are both A. You
get around this with a syntax like:

class B : public virtual A {};

It's basically just a big hack built into C++. :)

-J





More information about the tuxCPProgramming mailing list