lec0204-dtors - Todays announcements: MP2 available, due...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Today’s announcements: MP2 available, due 2/8, 11:59p. 2 instances in which the system deploys the copy constructor:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copy constructor: class sphere{ public: sphere(); sphere(double r); sphere(const sphere & orig); void setRadius(double newRad); double getDiameter() const; private: double theRadius; int numAtts; string * atts; }; //copy constructor sphere::sphere(const sphere & orig) { }
Background image of page 2
class sphere{ public: sphere(); sphere(double r); sphere(const sphere & orig); void setRadius(double newRad); double getDiameter() const; private: double theRadius; int numAtts; string * atts; }; int main(){ sphere s; …// initialize s sphere t(s); //invokes CC return 0; } Poser: cctor - why pbr? //copy constructor sphere::sphere( const sphere & orig ): theRadius(orig.theRadius),numatts(orig.numAtts) { atts = new string[numAtts]; for(int i=0; i<numAtts;i++) atts[i]= orig.atts[i]; } red shiny juicy s 1.0 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Destructors: class sphere{ public: sphere(); sphere(double r); sphere(const sphere & orig); ~sphere(); private: double theRadius; int numAtts; string * attributes; }; void myFun(sphere s){ sphere t(s); // play with s and t } int main(){ sphere a; // initialize a myFun(a); return 0; } 3.2 3 Red Shiny juicy
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/26/2012 for the course CS CS 225 taught by Professor Heeren during the Spring '09 term at University of Illinois, Urbana Champaign.

Page1 / 12

lec0204-dtors - Todays announcements: MP2 available, due...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online