[LC++]Pure Virtual Functions and Derived Classes
Paul M Foster
paulf at quillandmouse.com
Mon Apr 29 16:24:05 UTC 2002
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
More information about the tuxCPProgramming
mailing list