content.html 655 B

1234567891011121314151617
  1. <p>
  2. Virtual member functions are key to the object-oriented paradigm,
  3. such as making it easy for old code to call new code.
  4. A virtual function allows derived classes to replace the implementation
  5. provided by the base class. The compiler makes sure the replacement is
  6. always called whenever the object in question is actually of the derived class,
  7. even if the object is accessed by a base pointer rather than a derived pointer.
  8. This allows algorithms in the base class to be replaced in the derived class,
  9. even if users dont know about the derived class.
  10. <code>
  11. class A {
  12. public:
  13. virtual void foo() {}
  14. }
  15. </code>
  16. </p>