/*----
  signature: main: void -> int
  purpose: some demos of default copy constructor and
      default overloaded assignment operator
      behavior

  compile using:
    g++ 112lect08-1-reminder.cpp PlayerChar.cpp -o 112lect08-1-reminder
  run using:
    ./112lect08-1-reminder

  by: Sharon Tuttle
  last modified: 2022-10-11
----*/

#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include "PlayerChar.h"    
using namespace std;

// UGLYbad function! No biscuit!

void badfunct(PlayerChar a_player)
{
    a_player.set_role("*** COMIC RELIEF ***");
    cout << endl;
    cout << "Who, me? Do something I should NOT?" << endl;
    cout << "a_player is: " << a_player.player_to_string() << endl;
}

int main()
{
    cout << boolalpha;

    cout << endl
         << "demoing default overloaded assignment operator"
         << endl << "   for classes: " << endl;
    
    PlayerChar alphonse("Alphonse", 25, 10.6, "armour", 30);
    PlayerChar edward;
    
    edward = alphonse;

    // If you assign alphonse to edward, what does that mean?
    // The default OVERLOADED ASSIGNMENT OPERATOR generated for
    //     PlayerChar copies the value in alphonse's data
    //     fields into edward's data fields.

    // here, you can see they are in different locations in
    //    memory:

    cout << endl;
    cout << "alphonse's address: "
         << &alphonse << endl;
    cout << "edward's address:   "
         << &edward << endl;    

    // but they have equivalent data fields:

    cout << endl;
    cout << "alphonse's data fields: "
         << alphonse.player_to_string() << endl;
    cout << "edward's data fields:   "
         << edward.player_to_string() << endl;

    // and if you change edward's name field, in ONLY
    //    changes edward's name, it does NOT also
    //    change alphonse's name

    edward.set_name("Edward");

    cout << endl << "after edward's name change: " << endl;

    cout << "alphonse's data fields: "
         << alphonse.player_to_string() << endl;
    cout << "edward's data fields:   "
         << edward.player_to_string() << endl;

    // calling the ugly function above to demo
    //     PlayerChar's default copy constructor

    badfunct(edward);

    cout << endl;
    cout << "after call of badfunct, alphonse and edward "
         << endl << "   are: " << endl;
    cout << "alphonse's data fields: "
         << alphonse.player_to_string() << endl;
    cout << "edward's data fields:   "
         << edward.player_to_string() << endl;
    
    cout << endl;
    return EXIT_SUCCESS;
}