Playing around and trying to learn templates.
Soo my question is, how could I go about storing a template class in a pre declared vector?
Here is a small amount of code I've type up thus far
Configuration.cpp:
Code
template<class T>
CSettingValue<T>::CSettingValue(T& t_Obj, T t_Value, unsigned short type)
{
t_Obj = t_Value;
p_Obj = t_Obj;
u_Type = type;
}
Configuration.h:
Code
enum
{
BOOLEAN = 1,
STRING,
USHORT
};
template<class T>
class CSettingValue
{
private:
T* p_Obj;
T t_Value;
unsigned short u_Type;
public:
CSettingValue(T&, T, unsigned short);
};
What I would like to do is have a vector that will be used for managing various different data types of CSettingValue objects
i.e
Code
std::vector<CSettingValue*> settings;
settings.push_back(new CSettingValue<std::string>(v_StrDataMember, "value", STRING));
settings.push_back(new CSettingValue<unsigned short>(v_UshortDataMember, 111, USHORT));
settings.push_back(new CSettingValue<bool>(v_BoolDataMember, true, BOOLEAN));
for(std::vector<CSettingValue*>::iterator it = settings.begin(); it != settings.end(); it++)
{
delete *it;
}
Something like that.. I suck with this template / polymorphism stuff atm. Suggestions?
This post was edited by SelfTaught on Oct 17 2013 12:01am