I was wondering if someone could help me.
Suppose I have some classes as follows:
class A { ... };
class B : public A { ... }
class C : public A { ... };
class D { ... };
class E : public D { ... };
class F : public D { ... };
Now I want class B to have an object of type E as a member and class C to have a object of type F as a member.
Is there a nice design pattern whereby I can have some sort of base pointer to class D in class A and then create a new E in class B and a new F in class C. I was wondering if abstract factory is similar?.
I hope this is not too confusing … it is hard to explain without UML diagrams!.
What’s wrong with just doing exactly as you say?
If you want to automate it a bit better, you can use an intermediate template class.
Note that
AImpl::getD()can returnT*due to covariant return types.