C++ Diamond of Doom with external SDK -


i have annoying multiple-inheritance diamond of doom complicated twist (we're talking ms com objects, detail relevant later) -

  • assume abstract class (interface) has pure virtual methods.
  • another abstract class (another interface) b derived , expands more pure virtual methods.
  • class c derived class , implements of abstract methods.
  • class d derived class b, implementing abstract methods both , b.

right have 2 classes c, d lot of copy-pasted code (since of required interface resides in class a). i'd avoid having d inherit c, d inherits b, creates classic diamond of doom issue.

i know can solved virtual inheritance, here's twist in plot: classes , b com interfaces, defined in sdk cannot modify (i.e. "a.h" , "b.h" read only). inheritance b not virtual , cannot modified. can modify classes c , d, must adhere defined interfaces.

i'd appreciate creative ideas on how overcome this.

i'm assuming details of question, problem have functions , not member variables of (which seems interface).

in case here 2 options spring mind.

1) have d own c rather inherit it.

class d : public b {     public:     virtual int fa()     {         return m_c.fa();     }     private: c m_c; }; 

or inherit privately c

class d : public b, private c {    public:    virtual int fa()    {       return c::fa();    }  }; 

where fa() pure virtual function in a

both cases involve defining function implement fa in d, actual implementation detail not duplicated.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -