STL iterator problem
Howdy Folks,
This should be an easy answer, but I read four or five tutorials and still couldnt figure it out. I have a linked list which is templated to contain (Character *) which represents a sprite in my program.
list* charList = new list();
...(add stuff in here)
now i wish to iterate through my list and draw each item:
list::iterator start = charList->begin();
list::iteraotr stop = charList->end();
for( ; start != stop; ++start)
**start->draw()!!!????
i cant figure out for the life of me how to dereference this correctly! I feel like I''ve tried every possible combination!
thanks,
dave
For your example you would need to do
(*start)->draw();
You should really think about using the "proper" STL way of doing things and look up the for_each method (which can be found, along with many other useful methods, in the header file).
(*start)->draw();
You should really think about using the "proper" STL way of doing things and look up the for_each method (which can be found, along with many other useful methods, in the header file).
---Ranok---
#include<algorithm>
#include<functional>
std::for_each( start, stop, std::mem_fun( &Character::draw ) );
edit : added headers and scope prefix
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on February 15, 2003 10:46:18 AM]
#include<functional>
std::for_each( start, stop, std::mem_fun( &Character::draw ) );
edit : added headers and scope prefix
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on February 15, 2003 10:46:18 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement