// assignment operator KMfilterCenters& KMfilterCenters::operator=(const KMfilterCenters& s) { if (this != &s) { // avoid self copy (x=x) // different sizes? if (kCtrs != s.kCtrs || getDim() != s.getDim()) { kmDeallocPts(sums); // deallocate old storage delete [] sumSqs; delete [] weights; delete [] dists; // allocate new storage sums = kmAllocPts(s.kCtrs, s.getDim()); sumSqs = new double[s.kCtrs]; weights = new int[s.kCtrs]; dists = new double[s.kCtrs]; } KMcenters& base = *this; base.operator=(s); // copy base class // copy array contents kmCopyPts(kCtrs, getDim(), s.sums, sums); kmCopy(kCtrs, s.sumSqs, sumSqs); kmCopy(kCtrs, s.weights, weights); kmCopy(kCtrs, s.dists, dists); valid = s.valid; } currDist = s.currDist; dampFactor = s.dampFactor; return *this; }
// assignment operator KMcenters& KMcenters::operator=(const KMcenters& s) { if (this != &s) { // avoid self assignment (x=x) // size change? if (kCtrs != s.kCtrs || getDim() != s.getDim()) { kmDeallocPts(ctrs); // reallocate points ctrs = kmAllocPts(s.kCtrs, s.getDim()); } kCtrs = s.kCtrs; pts = s.pts; kmCopyPts(kCtrs, s.getDim(), s.ctrs, ctrs); } return *this; }