// cd.cc   Experiments with constructors and destructors
//        When are they called?   P. Conrad for CISC220 06J

#include "cd.h"

#include <iostream>
using std::cerr;
using std::endl;


CD_C::CD_C(int theX, const char * const theLabel) :
  f(theLabel), g("")
{
#ifdef DEBUG_CD
  cerr << "Entering (1) CD_C(int theX); " << endl;
#endif

  x = theX;

#ifdef DEBUG_CD
  cerr << "Exiting (1) CD_C(int theX); " << endl;
#endif
}

CD_C::CD_C() : f(""), g("")
{
#ifdef DEBUG_CD
  cerr << "Entering (2) CD_C(); " << endl;
#endif

  x = 0;

#ifdef DEBUG_CD
  cerr << "Exiting (2) CD_C(); " << endl;
#endif
}

  

CD_C::CD_C(const CD_C & orig) :
  f(orig.f), g(orig.g)
{
#ifdef DEBUG_CD
  cerr << "Entering (3) CD_C(const CD_C & orig); (copy constructor) " << endl;
#endif

  x = orig.x;

#ifdef DEBUG_CD
  cerr << "Exiting (3) CD_C(const CD_C & orig); (copy constructor); " << endl;
#endif

}
CD_C & CD_C::operator = (const CD_C & right)
{

#ifdef DEBUG_CD
  cerr << "Entering (4) operator = (const CD_C & right)" << endl;
#endif

  x = right.x;
  f = right.f;
  g = right.g;

#ifdef DEBUG_CD
  cerr << "Exiting (4) operator = (const CD_C & right)" << endl;
#endif

  return (*this);

}

CD_C::~CD_C()
{
#ifdef DEBUG_CD
  cerr << "Entering (5) ~CD_C()" << endl;
  cerr << "Invoking the destructor for object with label " << f << endl;
#endif


#ifdef DEBUG_CD
  cerr << "Exiting (5) ~CD_C()" << endl;
#endif

}



ostream & operator << (ostream & left, const CD_C & right)
{
#ifdef DEBUG_CD
  cerr << "Entering (6) << (ostream & left, const CD_C & right) " << endl;
#endif


  right.print(left);
  return (left);

#ifdef DEBUG_CD
  cerr << "Exiting (6) << (ostream & left, const CD_C & right) " << endl;
#endif

}
