Effective C++ Ed. 3rd: Item 33. Avoid hiding inherited names

  • Names of functions, typedefs etc. in base class get "shadow"ed if anything with those names is present in derived class.
  • The function names get "shadow"ed irrespective of the arguments of the functions regardless of whether the functions are virtual or non-virtual.
  • Sometimes it's desirable to inherit the overloads. Use Base::functionName(); to make these visible in derived class.
  •  Say If we have Base::mf1(); and Base::mf1(int); But we only want former to be visible in derived class, the above trick won't work. Use forwarding functions as: derived::mf1(){ base::mf1() }
Note: For template classes, see item 43.
prev | next
Cheers and try hosting at Linode.

No comments:

Post a Comment