Design and Documentation ◾ 129
//copy constructor: new memory allocated, old values copied
goodMM::goodMM(const goodMM& x)
{ size = x.size;
copyData(x.heapData);
}
//overloaded assignment operator
// delete old lhs memory
// copy old values from rhs into new memory for lhs
void goodMM::operator=(const goodMM& rhs)
{ if (this != &rhs) //skip self-assignment
{ delete[] heapData;
size = rhs.size;
copyData(rhs.heapData);
}
return;
}
A private utility function may be used to internally adjust state. For
example, a resize() function may expand the size of a container. Why
should this method be private rather than public? e application pro-
grammer should not be responsible for maintaining the container in a
usable condition. When over ...