J
jayesah
Hi All,
List and its iterator work as following way :
list<int> mylist;
list<int>::iterator itr;
itr = mylist.begin();
cout << (*itr);
But I want something like this:
list<int> mylist;
MyIterator itr(mylist);
cout<< (*itr);
So I wrote MyIterator following way :
template <class T> class MyIterator : public list<T>::iterator
{
public:
MyIterator() { };
~MyIterator() { };
MyIterator(list<T>& mylist) {
/* What I should write here */
};
};
int main()
{
list<int> mylist;
mylist.push_back(1);
mylist.push_back(2);
/* I want to support following construct */
MyIterator iter(mylist);
cout <<*mylist;
return 0;
}
Can anybody please guide me what I should write in one parameter
constructor ? Or do you have all together different solution ?
The reason I derived MyIterator from list<T>::iterator is that I want
to support all the overloaded operator that list<T>::iterator supports.
Thanks
Jayesh Shah
List and its iterator work as following way :
list<int> mylist;
list<int>::iterator itr;
itr = mylist.begin();
cout << (*itr);
But I want something like this:
list<int> mylist;
MyIterator itr(mylist);
cout<< (*itr);
So I wrote MyIterator following way :
template <class T> class MyIterator : public list<T>::iterator
{
public:
MyIterator() { };
~MyIterator() { };
MyIterator(list<T>& mylist) {
/* What I should write here */
};
};
int main()
{
list<int> mylist;
mylist.push_back(1);
mylist.push_back(2);
/* I want to support following construct */
MyIterator iter(mylist);
cout <<*mylist;
return 0;
}
Can anybody please guide me what I should write in one parameter
constructor ? Or do you have all together different solution ?
The reason I derived MyIterator from list<T>::iterator is that I want
to support all the overloaded operator that list<T>::iterator supports.
Thanks
Jayesh Shah