Ooh, I know this feeling.
I had a setup with a factory that produced objects of base type A, the problem was that A was not generic enough for the purposes I wanted to use it for, so I set up another type, B, which could be used under those circumstances.
The problem was that when I produced A, I had a set of parameters that I had to configure on it, and I needed the same parameters configured on B, this meant I needed to reimplement a base class C for A in B. I say re-implement because there was another class specifying a certain behaviour for A, which also needed to exist on its own, but wasn't always necessary in B, and sometimes prohibitive:
A now inherits B and D.
B and D both inherit C.
This meant that I had now arrived at a famous problem, the
diamond problem.
Seeing as I worked in C++, I put some effort into figuring out how this problem worked, and what it meant.
What happens is that, since you have two of the same class in two different classes, you get two(!) instances of the classes connected by the diamond. Some more exploration revealed that inheriting virtual classes solved the problem and created some new ones in C++. I read onwards a bit, digressed onto other topics, then I realised my folly.
In the end, the solution was this:
B did not have to inherit C. Instead, this:
class C {/*...*/};
class D : public C{/*...*/};
class B {
public:
virtual C* getC() = 0;
};
class A : public D{
C* getC(){return this;}
};
Oh, the
.