/* teststack.cpp - Variation on Prof. LaFollette's code
 */

#include <iostream>
using namespace std;
#include "intstack.h"

void printit(IntStack s) //s is passed by value
{
  cout << "Printing inside function printit:" << endl;
  while (!s.isempty())
      cout << s.pop() << endl;
}

int main()
{
  IntStack a(5), b(6);

  for (int i = 0; !a.isfull(); i++)
      a.push(i);

  b = a;
  cout << "Contents of b:" << endl;
  while ( !b.isempty() )
  {
    cout << b.pop() << endl;
  }
  //Since now b is empty, I copy it back from a
  b = a;

  printit(a); //copy a into a function and print its contents

  cout << "Printing a directly:" << endl;
  while ( !a.isempty() )
  {
    cout << a.pop() << endl;
  }
  //Now a is empty, so I delete it
  a.~IntStack();
  //b should still have the original content
  printit(b);
  //b still has the original content since the class
  //IntStack defines an assignment operator that
  //does a "deep copy". If we use instead the "shallow copy"
  //assignment operator our life becomes horrid. Try it.
  return 0;
}

  
