[LC++]Pure Virtual Functions and Derived Classes
Marshall Pharoah
pharoahm at northnet.org
Fri May 3 14:08:05 UTC 2002
----- Original Message -----
From: "Jack Lloyd" <lloyd at acm.jhu.edu>
To: <tuxcpprogramming at 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
>
More information about the tuxCPProgramming
mailing list