Original Post
I am new to using templates and was wondering how I can go about doing the following. I have a base template class called Field:
I would like to have class called Record that contains a set of Field instances in an stl container. The problem is I want the Record to contain different types of Fields, i.e.
How do I go about declaring a vector like that? Also I need some methods of the Record class to return the data contained in a specified Field, and this of course is dependent upon the Field itself. This little has caused me no end of frustration.
[edited by - paleraider on May 8, 2003 9:11:08 PM]
[edited by - paleraider on May 8, 2003 9:12:10 PM]
[edited by - paleraider on May 8, 2003 9:13:09 PM]
[edited by - paleraider on May 8, 2003 9:14:12 PM]
template <class Item>
class Field{
private:
Item data
std::string strName
explicit Field(std::string name, Item value): strName(name),m_iData(value){
}
~Field(){}
const Item& getData()const{
return data
}
const std::string& getName()const{
return strName
}
void setData(Item data){
m_iData = data;
}
void setName(std::string name){
m_strName = name;
}
};
Field<int>, Field<string>, and Field<float>