Home > C++ > Fully Qualified

Fully Qualified

When I’m coerced into inheriting from one or more base classes to reuse pre-existing functionality, I prefer to fully qualify my calls to base class member functions like this:

Coding this way helps me to keep a conceptual separation between classes and eases downstream maintenance – I know where to look for the function definitions. Since I’m a “has a” instead of an “is a” programmer, I prefer black box composition over white box inheritance; unless it’s necessary or authoritative coercion is involved. How about you? What’s your preference?

  1. March 15, 2011 at 10:31 pm

    Under the Windows environment, I use the keyword __super. In Linux environment, I just typedef __super with the parent class.

    It’s subjective, but I feel that it is cleaner because it distinguishes super class method calls and static member function calls from some helper class.

    When it comes to multiple inheritance (fairly rare), I usually follow your example and use the fully qualified name.

    … Alan

    • March 16, 2011 at 3:15 am

      Thanks for weighing in Alan. I didn’t know about the Win compiler __super keyword. I think any “idiom” that allows a maintainer to easily distinguish between calls to the base class(es) is great.

      Because of the potential to introduce nasty, hard to find bugs & deadly diamonds, I think MI should be used rarely too. Alas, I’ve had to work in several code bases where there’s lots of MI mixins – with some classes inheriting multiply from up to 3 classes. D’Oh!

  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.