COM SCI 31 Lecture Notes - Lecture 18: Class Invariant, Dont, Dangling Pointer

29 views2 pages
14 Aug 2017
School

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents