[LC++]Pure Virtual Functions and Derived Classes
Marshall Pharoah
pharoahm at northnet.org
Tue Apr 30 10:28:06 UTC 2002
Yes, derived classes must contain a defiition for all virtual functions.
Also, you may not create an instance of a firtual base class.
Marshall
> -----Original Message-----
> From: tuxcpprogramming-admin at lists.linux.org.au
> [mailto:tuxcpprogramming-admin at lists.linux.org.au] On Behalf
> Of Paul M Foster
> Sent: Monday, April 29, 2002 2:24 AM
> To: Linux C++ List
> Subject: [LC++]Pure Virtual Functions and Derived Classes
>
>
> Is is true that where you have a pure virtual function in a
> base class, your derived classes _must_ contain a definition
> of that virtual function? Sample code:
>
> class alpha
> {
> private:
> int x;
> public:
> alpha() {x = 0;}
> virtual void increment();
> virtual void decrement();
> virtual void turn_sideways() = 0;
> };
>
> class bravo : public alpha
> {
> public:
> void increment() { x += 1; }
> void decrement() { x -= 1; }
> // notice no reference to turn_sideways()
> };
>
>
>
> Paul
>
>
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List
>
More information about the tuxCPProgramming
mailing list