"Talha" <ta*********@hotmail.com> wrote...
Hi,
I have a general question about iterators
suppose I have a class
class MyClass
{
public:
....
private:
PtrList m_ptrlist<somerecordtype>;
Huh? Didn't you mean
PtrList<somerecordtype> m_ptrlist;
???
}
;
PtrList<T> is a class taht has an iterator implemented .. so i could
do:
m_ptrlist::iterator it = m_ptrlist.begin() .. and iterate / modify
items etc.
No, you couldn't. 'm_ptrlist' is not a type nor is it a namespace.
You have to do
PtrList<somerecordtype>::iterator it = ...
but suppose i want MyClass to be able to iterate over this list and
present that iteration interface to the user . what is the correct
way to do this?
There probably more than one correct way. You could define your own
type (MyClass::iterator, for example) by typedef'ing the PtrList's
one:
class MyClass {
...
typedef PtrList<somerecordtype>::iterator iterator;
};
and then provide your own 'begin', and 'end' member functions that
would return the right iterators:
class MyClass {
...
iterator begin() { return m_ptrlist.begin(); }
iterator end() { return m_ptrlist.end(); }
};
That ought to do it...
Victor