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;
}
|