Sams Teach Yourself C++ in 21 Days

(singke) #1
Advanced Inheritance 575

16


136: }
137: private:
138: PartNode * pHead;
139: int itsCount;
140: static PartsList GlobalPartsList;
141: };
142:
143: PartsList PartsList::GlobalPartsList;
144:
145: // Implementations for Lists...
146:
147: PartsList::PartsList():
148: pHead(0),
149: itsCount(0)
150: {}
151:
152: PartsList::~PartsList()
153: {
154: delete pHead;
155: }
156:
157: Part* PartsList::GetFirst() const
158: {
159: if (pHead)
160: return pHead->itsPart;
161: else
162: return NULL; // error catch here
163: }
164:
165: Part * PartsList::operator[](int offSet) const
166: {
167: PartNode* pNode = pHead;
168:
169: if (!pHead)
170: return NULL; // error catch here
171:
172: if (offSet > itsCount)
173: return NULL; // error
174:
175: for (int i=0;i<offSet; i++)
176: pNode = pNode->itsNext;
177:
178: return pNode->itsPart;
179: }
180:
181: Part* PartsList::Find(int & position, int PartNumber) const
182: {
183: PartNode * pNode = 0;
184: for (pNode = pHead, position = 0;
185: pNode!=NULL;
186: pNode = pNode->itsNext, position++)
187: {

LISTING16.7 continued

Free download pdf