Effective C++ Ed. 3rd: Item 36. Never redefine an inherited non-virtual function

When base class pointer points to a derived class pointer and an inherited non-virtual function which is refined in derived class, the definition present in base class would execute. This happens because non-virtual functions are statically bind. So
  1. Either declare only those functions non-virtual which will remain invariant in derived classes
  2. Or use virtual functions or it's alternatives at defines here.
prev | next

Cheers

No comments:

Post a Comment