COM SCI 31 Lecture Notes - Lecture 18: Class Invariant, Dont, Dangling Pointer
Document Summary
//called on (i. e. the object pointed to by this) public: Target(); // constructor; automatically called when object created bool move(char dir); int position() const; //f promises not to modify the object that it"s void replayhistory() const; private: // pos == # of rs in history minus # of ls in history int pos; string history; << x. position() << endl; void report (const target& x) cout << there"s a target at position void playgame() Int ntargets = 0; if () addtargets(targets, ntargets, 3); int i; //targets[i] is a pointer! delete targets[1]; // gives object pointer points to back to operating system. //can only be used on new that hasn"t been deleted yet. // dangling pointer target[1] = target[2];// but the original *target[1] has no pointer; we can"t get to. For (int k = 0; k < n; k++) delete targets[k]; targets[k] = targets[n-1]; //delete and replace with the last.