Hi Guys,
Sorry, I realise I didn't leave much to go on, I was just wondering if there
was some simple syntax thing I was missing. Anyway, I have a bit more info,
I hope you can get enough from what I write.
I have a class called cField. I have another class called cFieldList, which
is derived from a template class, cList, which contains the std::vector. The
subscript operator function is declared in this base class. Here's cList
definition
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 cFieldList:
class cFieldList : public cList<cField> {
private:
// some stuff
public:
// c'tors etc
};
I then have a class called cDCF which basically opens a file, which contains
a public pointer to cFieldList:
class cDCF {
private:
// some stuff
public:
// c'tors etc
cFieldList* FieldList;
};
Ok, if I use cDCF in a program dynamically, ie:
cDCF *dcf = new dcf(filename);
and use:
cField f = dcf->FieldList[0];
I get a compile error: Could not find a match for
'cField:
perator=(cFieldList)'
However, if I make cFieldList* FieldList become cFieldList FieldList and use
cField f = dcf->FieldList[0];
the program compiles and runs fine, so it appears as though the [] operator
isn't working if it's class is dynamically declared. Any ideas why this is?
By the way, I am new to this, so may well be overlooking something stupid
that I don't yet understand!
Thanks for your patience,
Steve.
Steve said:
Hi, I hope someone can help.
I have a class called cField, and another class called cFieldList.
cFieldList contains a std::vector of cFields called myvec
I've overloaded the subscript operator for cFieldList as so:
cField& operator[](int pos) { return myvec[pos]; }
however, when I compile the following code, I get an error:
cField f = MyFieldList[1]; // this an example, assume the objects exists
correctly
The compiler returns - Could not find a match for 'cField:
perator
=(cFieldList)'
Anybody any ideas what I'm doing wrong?
Thanks in advance,
Steve.