home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX0910.CPP
- // demonstration of overloaded new operator
- //
- //------------------------------------------------------------
- // The Microsoft Visual C++ compiler has a different syntax
- // for customizing the new operator.
- // This example does not compile in Visual C++.
- //------------------------------------------------------------
-
- // Files used in this example:
- //------------------------------------------------------------
- // %F,15,EX09101.H%EX09101.H
- // %F,15,EX09101.CPP%EX09101.CPP
- // EX0910.CPP this file
- //------------------------------------------------------------
-
- #include <iostream.h>
- #include "EX09101.H"
-
- void main()
- {
-
- // points to the head of the list
- CachedNode* classList = new CachedNode;
-
- // used to point to a node in the list
- CachedNode* pClass = classList;
-
- // allocate 3 more nodes and add them to the list
- // the last node will be allocated using ::new
- for (int i = 1; i <= 3; i++)
- {
- pClass->Next(new CachedNode);// create and add a node
- pClass = pClass->Next(); // point to new node
- }
-
- // deallocate all the elements in the list
- // Notice that the last node is deallocated using ::new
- for (int j = 1; j <= 4; j++)
- {
- pClass = classList; // point to first node
- classList = pClass->Next(); // removed first node
- delete pClass; // delete node
- }
- }
-