Sams Teach Yourself C++ in 21 Days

(singke) #1
86: private:
87: Part *itsPart;
88: PartNode * itsNext;
89: };
90:
91:
92: PartNode::PartNode(Part* pPart):
93: itsPart(pPart),
94: itsNext(0)
95: {}
96:
97: PartNode::~PartNode()
98: {
99: delete itsPart;
100: itsPart = 0;
101: delete itsNext;
102: itsNext = 0;
103: }
104:
105: // Returns NULL if no next PartNode
106: PartNode * PartNode::GetNext() const
107: {
108: return itsNext;
109: }
110:
111: Part * PartNode::GetPart() const
112: {
113: if (itsPart)
114: return itsPart;
115: else
116: return NULL; //error
117: }
118:
119:
120: // **************** Part List ************
121: class PartsList
122: {
123: public:
124: PartsList();
125: ~PartsList();
126: // needs copy constructor and operator equals!
127: void Iterate(void (Part::*f)()const) const;
128: Part* Find(int & position, int PartNumber) const;
129: Part* GetFirst() const;
130: void Insert(Part *);
131: Part* operator[](int) const;
132: int GetCount() const { return itsCount; }
133: static PartsList& GetGlobalPartsList()
134: {
135: return GlobalPartsList;

574 Day 16


LISTING16.7 continued
Free download pdf