Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualGeometrian

Posted 21 January 2013 - 08:38 PM

Hi,

I have two classes in a library (can't be changed) named "LibBase" and "LibChild". I have three classes that I am writing named "AppBase", "AppChild1", "AppChild2".

Other classes need "AppBase" to be treatable like a "LibBase", yet this class is instantiated through "AppChild1" and "AppChild2", which provide special implementations.

Consequently, I have organized the classes into the following structure:

              LibBase
                 |
           ______|_____
          |            |
          |            |
          v            v
       AppBase      LibChild
          |            |
    ______|_____   ____|
   |            | |
   |            | |
   v            v v
AppChild1    AppChild2


This is the classic "diamond" multiple inheritance problem.  Unfortunately, "LibChild" is not virtually inherited from "LibBase".  There's also the added complication of "AppChild1".


To clarify the behavior I want:

  • Instantiations of "AppChild1" and "AppChild2" to be treatable as instances of "AppBase"
  • Instantiations of "AppChild1" and "AppChild2" to be treatable as instances of "LibBase"
  • When constructed, "AppChild1" constructs "LibBase" through "AppBase"
  • When constructed, "AppChild2" constructs "LibBase" through "LibChild"


Once again, the code in the libraries ("LibBase", "LibChild") is immutable, and no virtual inheritance is used in them.

I don't really know what to do here--I think I'm stuck.  I am not a C++ expert, so I'm hoping that I'm just not seeing a solution that's there or that someone can show that it's not solvable.  Any suggestions?


Thanks,
-G


#2Geometrian

Posted 21 January 2013 - 08:37 PM

Hi,

I have two classes in a library (can't be changed) named "LibBase" and "LibChild". I have three classes that I am writing named "AppBase", "AppChild1", "AppChild2".

Other classes need "AppBase" to be treatable like a "LibBase", yet this class is instantiated through "AppChild1" and "AppChild2", which provide special implementations.

Consequently, I have organized the classes into the following structure:

              LibBase
                 |
           ______|_____
          |            |
          |            |
          v            v
       AppBase      LibChild
          |            |
    ______|_____   ____|
   |            | |
   |            | |
   v            v v
AppChild1    AppChild2


This is the classic "diamond" multiple inheritance problem.  Unfortunately, "LibChild" is not virtually inherited from "LibBase".  There's also the added complication of "AppChild1".

To clarify the behavior I want:

  • Instantiations of "AppChild1" and "AppChild2" to be treatable as instances of "AppBase"
  • Instantiations of "AppChild1" and "AppChild2" to be treatable as instances of "LibBase"
  • When constructed, "AppChild1" constructs "LibBase" through "AppBase"
  • When constructed, "AppChild2" constructs "LibBase" through "LibChild"


Once again, the code in the libraries ("LibBase", "LibChild") is immutable, and no virtual inheritance is used in them.

I don't really know what to do here--I think I'm stuck.  I am not a C++ expert, so I'm hoping that I'm just not seeing a solution that's there or that someone can show that it's not solvable.  Any suggestions?


Thanks,
-G


#1Geometrian

Posted 21 January 2013 - 08:36 PM

Hi,

I have two classes in a library (can't be changed) named "LibBase" and "LibChild". I have three classes that I am writing named "AppBase", "AppChild1", "AppChild2".

Other classes need "AppBase" to be treatable like a "LibBase", yet this class is instantiated through "AppChild1" and "AppChild2", which provide special implementations.

Consequently, I have organized the classes into the following structure:

              LibBase
                 |
           ______|_____
          |            |
          |            |
          v            v
       AppBase      LibChild
          |            |
    ______|_____   ____|
   |            | |
   |            | |
   v            v v
AppChild1    AppChild2


This is the classic "diamond" multiple inheritance problem.  Unfortunately, "LibChild" is not virtually inherited from "LibBase".  There's the added complication of "AppChild1".

To clarify the behavior I want:
Instantiations of "AppChild1" and "AppChild2" to be treatable as instances of "AppBase"
Instantiations of "AppChild1" and "AppChild2" to be treatable as instances of "LibBase"
When constructed, "AppChild1" constructs "LibBase" through "AppBase"
When constructed, "AppChild2" constructs "LibBase" through "LibChild"

Once again, the code in the libraries ("LibBase", "LibChild") is immutable, and no virtual inheritance is used in them.

I don't really know what to do here--I think I'm stuck.  I am not a C++ expert, so I'm hoping that I'm just not seeing a solution that's there or that someone can show that it's not solvable.  Any suggestions?


Thanks,
-G


PARTNERS