テンプレート関数で型Tの親を取得し、私は以下のクラスをしたと仮定型Tの親を見つけ、関数base_ofを実装しますか?私はテンプレート関数の型クラスTの親が何であるかを知りたい
編集:私は私のためのオブジェクトを作成するファクトリクラスまし
:registerType機能で
template <typename B>
class Factory{
public:
template <typename D>
void registerType(std::string name)
{
static_assert(std::is_base_of<B, D>::value, "class doesn't derive from the base");
table_[name] = &createFunc<D>;
}
B* create(std::string name)
{
const auto it = table_.find(name);
if(it != table_.end())
return it->second();
FILE_LOG(logERROR) << "unidentified option, acceptable options are:";
for(auto const &m : list())
FILE_LOG(logERROR) << '\t' << m;
return nullptr;
}
std::vector<std::string> list()
{
std::vector<std::string> lst;
for(auto const &iter : table_)
lst.push_back(iter.first);
return lst;
}
private:
template<typename D>
static B* createFunc()
{
return new D();
}
typedef B* (*PCreateFunc)();
std::map<std::string, PCreateFunc> table_;
};
を私はタイプDのいくつかのプロパティを設定したい確かに私が何をしたい ですまたは親であり、次にcreate関数では、それに基づいてオブジェクトを作成したいと思います。
を扱っていませんか?私のためにXY問題のように聞こえる。 –
多重継承ではどうしたらいいですか? – Quentin
私は、ファクトリクラス(抽象ファクトリデザインパターンに基づいています)を作成すると、オブジェクトがそのプロパティまたはその親をチェックし、次にそれ(プロパティの値)によってオブジェクトが作成されます。私はそのタイプが何で、そのタイプが何であるかを知りたいです。 – abdolahS