mandrews58
June 19th, 2002, 12:11 PM
Thanks for any help on this:
say i define a class which handles a list of structures
class MyList{
public:
/*
constructor creates array of ListItems along the lines of:
pList = new ListItem[nElements];
*/
MyList(UINT nElements);
// subscript operator retruns ListItem reference
ListItem &operator[](UINT pos);
private:
ListItem *pList;
};
struct ListItem {
char strA[32];
char strB[32];
};
i want to use this as follows:
MyList *pList = new MyList(20);
strcpy(pList[3].strA, "Hi There");
the problem is that although operator[] returns a ListItem reference it is still a member of MyList, so pList[3].strA attempts to access a member of MyList and this will not compile. how do i get the functionality where the member access operator looks for a ListItem member, not a MyList member?
say i define a class which handles a list of structures
class MyList{
public:
/*
constructor creates array of ListItems along the lines of:
pList = new ListItem[nElements];
*/
MyList(UINT nElements);
// subscript operator retruns ListItem reference
ListItem &operator[](UINT pos);
private:
ListItem *pList;
};
struct ListItem {
char strA[32];
char strB[32];
};
i want to use this as follows:
MyList *pList = new MyList(20);
strcpy(pList[3].strA, "Hi There");
the problem is that although operator[] returns a ListItem reference it is still a member of MyList, so pList[3].strA attempts to access a member of MyList and this will not compile. how do i get the functionality where the member access operator looks for a ListItem member, not a MyList member?