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

Re: [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
> 


    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