When to Use a Pure Virtual Member Function

When to Use a Pure Virtual Member Function

A pure virtual function is merely an interface and can be thought of as a way to enforce policy. A pure virtual function should be used when subclasses implement the same interface completely differently. For example, a persistence interface can have a write operation to store the state of an object. Yet, each class that implements this interface performs individual operations to store its state into a file:

 class persistent {public:  virtual void Write () = 0;};class Clock: public persistent { public:  void Write() {_} // implement the interface};class Date: public persistent {public:  void Write() {_} // implement the interface};


Share the Post: