| | 1 | == list == |
| | 2 | [[TracNav(TracNav/TOCCode)]] |
| | 3 | There is a list template called "tList" use it as follows: |
| | 4 | |
| | 5 | === Use in Functions without Global Reference === |
| | 6 | It you just want to create a new list and just quickly use it make it as follows: |
| | 7 | {{{ |
| | 8 | #!cpp |
| | 9 | #include <list> /* include the header */ |
| | 10 | #include "debug.h" /* for use of PRINTF */ |
| | 11 | . |
| | 12 | . |
| | 13 | . |
| | 14 | std::list<char*> nameList; /* create the new list*/ |
| | 15 | |
| | 16 | nameList.push_back("Pumba"); /* add some elements at the end of the list (back)*/ |
| | 17 | nameList.push_back("Mogli"); |
| | 18 | nameList.push_back("Timon"); |
| | 19 | |
| | 20 | std::list<char*>::iterator element; |
| | 21 | for (element = nameList.begin(); element != nameList.end(); element++) |
| | 22 | { |
| | 23 | PRINTF(3)("found name: %s in list\n", (*name)); |
| | 24 | } |
| | 25 | . |
| | 26 | . |
| | 27 | }}} |
| | 28 | This code will have an output like this: |
| | 29 | {{{ |
| | 30 | found name: Pumpa in list |
| | 31 | found name: Mogli in list |
| | 32 | found name: Timon in list |
| | 33 | }}} |
| | 34 | You can make lists of whatever you want eg also from WorldEntities: |
| | 35 | {{{ |
| | 36 | #!cpp |
| | 37 | #include <list> |
| | 38 | . |
| | 39 | . |
| | 40 | list<WorldEntity*>* entityList = new List<WorldEntity*>; /* crete new list*/ |
| | 41 | entityList->push_back(new WorldEntity()); /* just adds an new entity */ |
| | 42 | . |
| | 43 | . |
| | 44 | }}} |
| | 45 | |
| | 46 | Now I hear you screem: "ENOUGH"! And you are right...:) |
| | 47 | |
| | 48 | === Use in Header Files === |
| | 49 | If you want a list as a class attribute you have to make a forward declaration of the list: |
| | 50 | {{{ |
| | 51 | #!cpp |
| | 52 | #inlcude <list> /* include the header of the list */ |
| | 53 | |
| | 54 | class ExampleClass |
| | 55 | { |
| | 56 | private: |
| | 57 | list<> |
| | 58 | }; |
| | 59 | |
| | 60 | }}} |