class IObject
{
public:
virtual void create(void** ret_val) = 0;
virtual std::string name() const = 0;
};
template <typename _Type>
class ObjectT : public IObject
{
protected:
static std::string m_name;
public:
void create(void** ret_val)
{
*ret_val = (void*) new _Type;
}
};
typedef ObjectT<bool> BoolObject;
typedef ObjectT<int> IntObject;
template<> std::string BoolObject::m_name = "bool";
template<> std::string IntObject::m_name = "int";
BoolObject bobj;
IntObject iobj;
std::vector<IObject*> my_vector;
my_vector.push_back (&bobj);
my_vector.push_back (&iobj);
if (my_vector[n].name() == "bool") {
bool* pval = nullptr;
my_vector[n].create((void**) &pval);
*pval = true;
}