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

#include "foo.h"

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


Foo_C::Foo_C(const char * const theLabel)
{
#ifdef DEBUG_FOO
  cerr << "Entering (7) Foo_C(const char * const theLabel); " << endl;
#endif

  label = new char [strlen(theLabel)+1];
  strcpy(label,theLabel);

#ifdef DEBUG_FOO
  cerr << "Exiting (7);" << endl;
#endif
}


Foo_C::Foo_C()
{
#ifdef DEBUG_FOO
  cerr << "Entering (8) Foo_C(); " << endl;
#endif

  label=new char[1];
  strcpy(label,""); // OR label[0] = '\0';  OR (*label) = '\0';

#ifdef DEBUG_FOO
  cerr << "Exiting (8) " << endl;
#endif
}


  

Foo_C::Foo_C(const Foo_C & orig)
{
#ifdef DEBUG_FOO
  cerr << "Entering (9) Foo_C(const Foo_C & orig); (copy constructor) " << endl;
#endif

  label = new char [strlen(orig.label)+1];
  strcpy(label,orig.label);

#ifdef DEBUG_FOO
  cerr << "Exiting (9)  " << endl;
#endif

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

#ifdef DEBUG_FOO
  cerr << "Entering (10) operator = (const Foo_C & right)" << endl;
#endif

  if (&right == this)
    return (*this);

  delete [] label;

  label = new char [strlen(right.label) + 1];
  strcpy(label,right.label);


#ifdef DEBUG_FOO
  cerr << "Exiting (10) " << endl;
#endif

  return (*this);

}



Foo_C::~Foo_C()
{
#ifdef DEBUG_FOO
  cerr << "Entering (11) ~Foo_C()" << endl;
#endif

  delete [] label;

#ifdef DEBUG_FOO
  cerr << "Exiting (11) ~Foo_C()" << endl;
#endif

}



ostream & operator << (ostream & left, const Foo_C & right)
{
#ifdef DEBUG_FOO
  cerr << "Entering (12) << (ostream & left, const Foo_C & right) " << endl;
#endif

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

#ifdef DEBUG_FOO
  cerr << "Exiting (12) " << endl;
#endif

}
