Advanced Inheritance 565
16
93: {}
94:
95: PartNode::~PartNode()
96: {
97: delete itsPart;
98: itsPart = 0;
99: delete itsNext;
100: itsNext = 0;
101: }
102:
103: // Returns NULL if no next PartNode
104: PartNode * PartNode::GetNext() const
105: {
106: return itsNext;
107: }
108:
109: Part * PartNode::GetPart() const
110: {
111: if (itsPart)
112: return itsPart;
113: else
114: return NULL; //error
115: }
116:
117:
118:
119: // **************** Part List ************
120: class PartsList
121: {
122: public:
123: PartsList();
124: ~PartsList();
125: // needs copy constructor and operator equals!
126: void Iterate(void (Part::*f)()const) const;
127: Part* Find(int & position, int PartNumber) const;
128: Part* GetFirst() const;
129: void Insert(Part *);
130: Part* operator[](int) const;
131: int GetCount() const { return itsCount; }
132: static PartsList& GetGlobalPartsList()
133: {
134: return GlobalPartsList;
135: }
136: private:
137: PartNode * pHead;
138: int itsCount;
139: static PartsList GlobalPartsList;
140: };
141:
142: PartsList PartsList::GlobalPartsList;
143:
144:
LISTING16.6 continued