S
Steve
Hi, I have a class called cList as so:
template<class T> class cList { // base class for Lists
private:
protected:
vector<T> tListOf; // field list container
public:
void Add(const T& t) {tListOf.push_back(t);} // add new object to list
unsigned int Count() { return tListOf.size(); } // number of list items
cList(); // default constructor
cList(const cList&); // copy constructor
cList& operator=(const cList&); // assignment constructor
virtual ~cList(); // destructor
T& operator[](int& pos) {return tListOf[pos];} // subscript operator
const T& operator[](const int& pos) {return tListOf[pos];} // subscript
operator
};
This is inherited by another class, cDataList, and another, cResultList. The
data list object is a list of cData objects, and the result list is a list
of cResult objects.
class cResultList : public cList<cResult> {
private:
// some stuff
public:
// c'tors etc
};
class cDataList : public cList<cData> {
private:
// some stuff
public:
// c'tors etc
cResultList Results;
};
The cDataList object contains a cResultList object called Results.
I then have a class called cDCF like so:
class cDCF {
private:
// some stuff
public:
// c'tors etc
cDataList Data;
};
My problem is, I'm struggling to access the elements of Results (the cResult
class has a 'value' member):
cDCF *dcf = new cDCF(myfilename);
float f = dcf->Data[1].Results[1].value;
This gives a compiler error saying:
operator+ not implemented in type cResultList for arguements of type 'int'
however, if I use this:
cDCF *dcf = new cDCF(myfilename);
cData d = dcf->Data[1];
float f = d.Results[1].value;
this works. Now I know it's something to do with how I'm using the subscript
operator, but I'm not sure what. Can anybody see what I'm doing wrong
please?
Thanks for your time,
Steve
template<class T> class cList { // base class for Lists
private:
protected:
vector<T> tListOf; // field list container
public:
void Add(const T& t) {tListOf.push_back(t);} // add new object to list
unsigned int Count() { return tListOf.size(); } // number of list items
cList(); // default constructor
cList(const cList&); // copy constructor
cList& operator=(const cList&); // assignment constructor
virtual ~cList(); // destructor
T& operator[](int& pos) {return tListOf[pos];} // subscript operator
const T& operator[](const int& pos) {return tListOf[pos];} // subscript
operator
};
This is inherited by another class, cDataList, and another, cResultList. The
data list object is a list of cData objects, and the result list is a list
of cResult objects.
class cResultList : public cList<cResult> {
private:
// some stuff
public:
// c'tors etc
};
class cDataList : public cList<cData> {
private:
// some stuff
public:
// c'tors etc
cResultList Results;
};
The cDataList object contains a cResultList object called Results.
I then have a class called cDCF like so:
class cDCF {
private:
// some stuff
public:
// c'tors etc
cDataList Data;
};
My problem is, I'm struggling to access the elements of Results (the cResult
class has a 'value' member):
cDCF *dcf = new cDCF(myfilename);
float f = dcf->Data[1].Results[1].value;
This gives a compiler error saying:
operator+ not implemented in type cResultList for arguements of type 'int'
however, if I use this:
cDCF *dcf = new cDCF(myfilename);
cData d = dcf->Data[1];
float f = d.Results[1].value;
this works. Now I know it's something to do with how I'm using the subscript
operator, but I'm not sure what. Can anybody see what I'm doing wrong
please?
Thanks for your time,
Steve