CS 225 Lecture 8: Destructors and Operators

28 views6 pages

Document Summary

Class sphere{ public: sphere(); sphere(const sphere & orig); private: double theradius; int numatts; string * atts; // putting consts before or after the type are equivalent ex. // const sphere & vs sphere const & // pass by value calls cctor bad. // we need to because atts exists. and atts use dynamic memory. Class sphere { public: sphere(); sphere(double r); sphere(const sphere & orig); Cs 225 - lecture page 1 sphere(const sphere & orig); Private: double theradius; int numatts; string * atts; void myfune(sphere s) { sphere t(s); // create a copy. // play with s and t int main() { sphere a; myfun(a); // for dynamic memory, default destructor isn"t enough. Destructors: class sphere { public: sphere(); sphere(double r); sphere(const sphere & orig); Cs 225 - lecture page 2 sphere(const sphere & orig); ~sphere(); private: double theradius; int numatts; string * atts; int main() {

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