I am working on a generic parameter checker in C++ that can add options and parse their content.
Here is my Param
class:
class Param
{
public:
Param();
~Param();
template <typename T>
void add_option(std::string, std::string, T&); // flag, description, storage value
protected:
std::map<std::string, IOption> options;
};
template <typename T>
void Param::add_option(std::string, std::string, T&) // Is templated to add an option depending on its type
{}
template<> void Param::add_option<int>(std::string, std::string, int &);
template<> void Param::add_option<std::string>(std::string, std::string, std::string &);
As you can see I wish to store up new options in a map
, here is the class Option and it's "interface":
template <typename T>
class Option : public IOption
{
public:
Option(std::string flag, std::string desc, T &ref) : flag_(flag), desc_(desc), ref_(ref) {}
~Option() {}
std::string getFlag()
{
return (flag_);
}
protected:
std::string flag_;
std::string desc_;
T &ref_;
};
class IOption
{
public:
virtual ~IOption() {}
IOption() {}
virtual std::string getFlag() = 0;
};
The reason why I have created this interface is to store up my options in the map even though they are templated.
But right now, I can't compile because
field type 'IOption' is an abstract class
What would be the best way to create a generic parameter checker from what I have in C++?