////////////////////////////////////// // program to demonstrate use of class list_item // using namespace std; #include #include "list-item.h" list_item* menu_root(0); static list_guard whatever(menu_root, "guard"); int main() { cout << "* first part of main()" << endl; list_item*& menu_head(menu_root->next); menu_head->dump(); // show initial state { // begining of temporary scope list_item kumquat(menu_root, "kumquat"); // add temporary item menu_head->dump(); // show new state including temporary item } // temporary item goes out of scope now menu_head->dump(); // show original state again cout << "* second part of main()" << endl; // Slightly simpler procedures are also available // when the root itself is a dynamic (local) variable: { list_item myroot("dynamic"); // create dummy root-item directly list_item*& myhead(myroot.next); list_item cat(myroot, "cat"); list_item dog(myroot, "dog"); list_item bird(&myroot, "bird"); myhead->dump(); // dump the local list } // myroot, cat, dog, and bird all go out of scope now cout << "* third part of main()" << endl; // Yet another set of procedures is available: { list_root myptr("game"); list_item*& myhead(myptr.root->next); list_item rock(myptr.root, "rock"); list_item paper(myptr.root, "paper"); list_item scissors(myptr.root, "scissors"); myhead->dump(); // dump the local list } // myptr, rock, paper, and scissors all go out of scope now cout << "* end of main()" << endl; }