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

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

using namespace std;

class PGStudent : public Student {
   int gyear;   // graduation year
public:
   PGStudent(const char* nam, int gy = 0) : Student(nam), gyear(gy)
   {  cout << "A PGStudent was just constructed"
           << " with Graduation year: " << gyear << endl; }
///*
   PGStudent(const PGStudent& pgs)
      : Student(pgs), // Is there any other possibility
                      // for initialization by copying?
        gyear(pgs.gyear)
   {  cout << "A PostGraduate Student was just created by copying"
           << endl; }
//*/
   ~PGStudent()
   {  cout << "Destroying a PGStudent" << endl; }

   int get_year() const
   {  return gyear; }
};

int main()
{
   PGStudent pgs1("FN1");

   cout << "Printing the graduation year from Main: "
        << pgs1.get_year() << endl;

// Inherited functions:
   pgs1.set_no(123);
   cout << "Printing the no from Main: " << pgs1.get_no() << endl;

   cout << "////////////////////////////////////////////" << endl;
   PGStudent pgs2("FN2",2004);
   cout << "Printing the graduation year from Main: "
        << pgs2.get_year() << endl;

   cout << "////////////////////////////////////////////" << endl;

   PGStudent pgs3(pgs1);  // Copy constructor invoked.
                          // IN CASE NO DEFINITION
                          // of COPY CONSTRUCTOR:
                          // - copy constructor of Student is used
                          // to copy the Student subobject
                          // - bitwise copy for the rest
   cout << "Last Printing from Main: " << pgs3.get_year() << endl;

   return 0;
}
