Note for myself: When to use pure virtual, simple virtual, non-virtual?

When designing a class:

  • Use pure virtual function if you are sure every derived class’ must have that function but you have no idea about its implementation. Pure virtual functions inherit only its interface in derived classes.
  • Use simple virtual function when such a function might be overrided in derived class’ otherwise can be used default implementation in base class. Simple virtual functions inherit its interface and default implementation in derived classes.
  • Use non-virtual function when you are sure derived class’ use that function exactly the same way in the base class. Non-virtual functions inherit its interface and mandatory implementation in derived classes.

OOP

103 Words

2018-09-07 03:00 +0300