Avoid multiple occurrences of a base

Sometimes the same base class (which should be a mixin) occurs more than once as an ancestor of a class (this often happens with MCollectible). However, only one version of a virtual function can exist for a given class, and it's only useful to have multiple occurrences of a base class if there are data members associated with it.

Although you might need to have the same base class occur more than once, there are costs: there are multiple virtual table pointers and clients who want to cast to the base class that have to supply a casting path to indicate which of the duplicates the cast is for. If you don't need to cast back, and you don't need two copies of the data, this is one of the situations where virtual base classes might be better.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker