// The compilation command is:
// g++ 244.cc ../chapter5/162/student_constr.cpp

#include<iostream>
#include"../chapter5/162/student_constr.h"

using namespace std;

class Date {
   int day; int month; int year;
public:
   Date(int d = 1, int m = 1, int y = 2005)
      : day(d), month(m), year(y)
   {  cout << "A Date was just created with value: "
           << day << ' ' << month << ' ' << year << endl; }

   Date(const Date& d) : day(d.day), month(d.month), year(d.year)
   {  cout << "A Date was just created by copying" << endl; }

   ~Date()
   {  cout << '\n' << "Destroying a Date with value: "
           << day << ' ' << month << ' ' << year << endl; }

   void print() const
   {  cout << day << ' ' << month << ' ' << year << endl; }
};

class PGStudent : public Student {
   Date gdate;    // graduation date
public:
   PGStudent(const char* nam) : Student(nam)
   {  cout << "A PGStudent was just constructed " << endl;
      cout << "The Graduation date was :" << endl;
      this -> gdate.print(); }

   PGStudent(const char* nam, int gd, int gm)
      : Student(nam), gdate(gd,gm)
   {  cout << "A PGStudent was just constructed " << endl;
      cout << "The Graduation date was :" << endl;
      this -> gdate.print(); }

   ~PGStudent()
   {  cout << "Destroying a PGStudent" << endl; }

   Date get_date() const
   {  return gdate; }
// const Date& get_date() const { return gdate; }
                                   // CAREFUL: direct access
                                   // to privately named area
};

int main()
{
   PGStudent pgs1("FN");
// PGStudent pgs2("NFN", 22, 5);

   PGStudent pgs3(pgs1);

   cout << "////////////////////////////////////" << endl;
// pgs1.get_date().print(); // Careful:
                            // invokes copy constructor and
                            // destructor of Date for the
                            // temporary return object of get_date

   cout << "Ending main" << endl;

   return 0;
}
