自分のためにコマンドラインパーサーを操作する。私はこのコンストラクトに問題があり、誰かが回避策を提案することを期待していることをすぐに知っていました。異なる/未知の種類のクラステンプレートを持つベクトルを初期化する
さまざまな種類のデータを含む可能性のあるvector
にパラメータの引数リスト(テンプレートに基づく)を格納します。しかし私の理解から、vector<template<type>>
を静的に定義する必要があります。複数の型を除く方法がありますか?ここで
は、私が何を意味するかの例です:あなたがC++ 11のソリューションを受け入れることができる場合
#include <vector>
#include <memory>
namespace clparser
{
class CommandLine {
private:
std::vector<Parameter<AnyType??>*> ArgumentList;
public:
void Add(Parameter<AnyType??>* Parameter) { ArgumentList.push_back(Parameter); }
};
template<typename T>
class Parameter {
private:
const char *ShortOption;
const char *LongOption;
const char *Description;
const bool RequiredField;
const char *DefaultValue;
public:
Parameter(const char *ShortOption, const char *LongOption, const char *Description, const bool RequiredField, const char *DefaultValue)
: ShortOption(ShortOption), LongOption(LongOption), Description(Description), RequiredField(RequiredField), DefaultValue(DefaultValue)
{
}
};
}
'boost :: any'ですか? –
私はブーストの依存関係がない方が好きですが、STLでこれを達成できない場合は...ありがとうございます。 – user0000001
C++ 17 'any'も' std'でも利用可能ですので –