CS 225 Lecture 8: Destructors and Operators

30 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+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers