I have a class hierarchy that uses template:
template <typename T>
class BaseClass
{
public:
BaseClass(const std::string& inputName)
:
myMember(std::make_shared<T>(inputName))
{}
private:
const std::shared_ptr<T> myMember;
};
class UsedByDerived
{
public:
UsedByDerived(const std::string& inputName)
:
myInputName(inputName)
{}
private:
const std::string myInputName;
};
class DerivedClass : public BaseClass<UsedByDerived>
{
public:
DerivedClass()
:
BaseClass<UsedByDerived>("X")
{}
};
I have multiple derived classes like this (each could have different constructor signatures), and I would like to do an abstract factory to handle the instantiation. The base factory is
template <typename T>
class BaseFactory
{
public:
virtual std::shared_ptr<BaseClass<T>> createProduct() = 0;
};
I'm wondering what the derived factory class should look like (or whether this is not going to work?), however it's not clear how it should be implemented...:
class DerivedFactory
{
public:
std::shared_ptr<BaseClass</* what should this be? */>> createProduct()
{
// what should this return?
}
};