I'm trying to achieve the following inheritance relation.
         Variable
       /         \
... GlobalVar  LocalVar ...
       \         / (either)
       ExtendedVar // Essentially with more fields
I basically want it to extend one of the subclass of Variable, and the choice is made at run time. The virtual inheritance doesn't fully solve the problem. If ExtendedVar inherits both GlobalVar and LocalVar and when I need to call some member funciton, I can't specify which base class to use for the function.
This code seems to work.
class ExtendedVar : public Variable /* ExtendedVar is-a Variable */ {
    Variable& var; // wraps a var in it. This is the var to extend.
    std::string some_field;
}
But it comes with an unnecessary copy of A in the inheritance. Or I could have a few more classes like ExtendedGlobalVar and ExtendedLocalVar, which are obviously bad for maintainence.
Any better options?
 
    