Need design help as I'm causing a diamond with multiple Inheritance

28 views Asked by At

My classes currently look like this:

GetAndSet{ 
    virtual int get() = 0;
    virtual void set() = 0;
}

WindowsGetAndSet : public GetAndSet{
    virtual int get();
    virtual void set();
}    

However, I've ran into some new constraints and I've realized that:

  • Sometimes I only need get methods
  • Whenever I use set methods I also need get methods

Thus, I'd like to do something like this:

Get{ 
    virtual int get() = 0;

}

Set : public Get{
    virtual void set() = 0;
}

WindowsGet : public Get{
    virtual int get();
}    

WindowsGetAndSet: public WindowsGet, public Set{
    // inherits the get methods from WindowsGet
    virtual void set();
}

This causes me to run into the Diamond Problem where WindowsGetAndSet is inheriting Get twice, once from Set and once from WindowsGet.

Can I simply have Set and WindowsGet use virtual inheritence to inherit Get, or do I need to think up a new design all together?

0

There are 0 answers