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

Re: [LC++]Pure Virtual Functions and Derived Classes



----- Original Message -----
From: "Jack Lloyd" <lloyd@acm.jhu.edu>
To: <tuxcpprogramming@lists.linux.org.au>
Sent: Tuesday, April 30, 2002 11:34 AM
Subject: RE: [LC++]Pure Virtual Functions and Derived Classes


> On Mon, 29 Apr 2002, Marshall Pharoah wrote:
>
> > Yes, derived classes must contain a defiition for all virtual functions.
>
> IF you wish to instantiate the class in question. This is pefectly legal
> (and often very useful):
>
> class A
>  {
>  virtual void foo() = 0;
>  virtual void bar() = 0;
>  };
>
> class B : public A
>  {
>  void foo() { /* do something */ }
>  };
>
> class C : public B
>  {
>  void bar() { /* do something else */ }
>  };
>
> You can't create an A or B, but you can create C. But you can certainly
> pass around pointers or references to A or B, and all are valid
> declarations.
>
> > 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).

True.
Thanks.

>
> -Jack
>
>
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List
>