Q&A: what if the assignment operator is implemented...

...as the following in the Instrument class?

class Instrument {
  Instrument& operator=(const Instrument& rhs);

Instrument& Instrument::operator=(const Instrument& rhs) {
  delete [] description;
  description =   new char[strlen(rhs.description) + 1];
  strcpy(description, rhs.description);
  return *this;      

guess what happen when one tries the following

Instrument c("another bond");
c = c; 

Category: C++ Quant > C++

No comments:

Post a Comment