Example Code for Leak 1

 <  Free Open Study  >  

Example Code for Leak #1

 class Point {   int x, y;   char* color; public:   Point(int, int, char*); }; // Note that the constructor allocates space // for the ''color'' data member but there is // no destructor to free this memory. Point:: Point(int new_x, int new y, char* col) {   x = new_x;  y = new_y;   color = new char[strlen(col)+1];   strcpy(color, col); } // The proper destructor would look like: Point::~Point() { delete color; } 
 <  Free Open Study  >  


Object-Oriented Design Heuristics
Object-Oriented Design Heuristics (paperback)
ISBN: 0321774965
EAN: 2147483647
Year: 1996
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net