[LC++]Pure Virtual Functions and Derived Classes
Uri.Shenderovich at lightscapenet.com
Uri.Shenderovich at lightscapenet.com
Thu May 16 18:39:07 UTC 2002
That's not what the man was asking, eventhough your answer is correct as
well, but the real answer should be : yes , it's true.
The derived class must contain a definition of derived PURE virtual
function ( that's not true regarding ordinar virtual function ).
Regards,
Uri
Shaul Karl
<shaulka at bezeqint.net> To: Paul M Foster <paulf at quillandmouse.com>, Linux C++ List
Sent by: <tuxcpprogramming at lists.linux.org.au>
tuxcpprogramming-admin at lists.l cc:
inux.org.au Subject: Re: [LC++]Pure Virtual Functions and Derived Classes
29/04/02 10:20
Please respond to
tuxcpprogramming
> 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
>
A class containing (or inheriting) one or more pure virtual
functions is recognized as an abstract base class by the compiler.
An attempt to create an independent class object of an abstract
base class results in a compile-time error.
Taken from `The C++ primer', 3rd edition, page 927.
--
Shaul Karl
email: shaulka(replace with the at - @ - character)bezeqint.net
_______________________________________________
This is the Linux C++ Programming List
: http://lists.linux.org.au/listinfo/tuxcpprogramming List
More information about the tuxCPProgramming
mailing list