S
sgrm123
Guest
Hi,
How to get index of a element in the cPtrList
class CAge
{
public:
CAge(int nAge){m_nAge=nAge;}
int m_nAge;
};
typedef CTypedPtrList <CPtrList, CAge*> CAgePtrList;
CAgePtrList list;
POSITION pos;
CAge *p1 = new CAge(21);
CAge *p2 = new CAge(40);
list.AddTail(p1);
list.AddTail(p2);
POSITION pos1 = list.GetHeadPosition();
POSITION pos2 = list.Find(p2,NULL);
int nIndex=pos2-pos1;
if I subtract pos2 from pos1 I am getting the value 12. I expect the value 1 since it is 2nd element.
How to get index of a element?
Continue reading...
How to get index of a element in the cPtrList
class CAge
{
public:
CAge(int nAge){m_nAge=nAge;}
int m_nAge;
};
typedef CTypedPtrList <CPtrList, CAge*> CAgePtrList;
CAgePtrList list;
POSITION pos;
CAge *p1 = new CAge(21);
CAge *p2 = new CAge(40);
list.AddTail(p1);
list.AddTail(p2);
POSITION pos1 = list.GetHeadPosition();
POSITION pos2 = list.Find(p2,NULL);
int nIndex=pos2-pos1;
if I subtract pos2 from pos1 I am getting the value 12. I expect the value 1 since it is 2nd element.
How to get index of a element?
Continue reading...