// example6.cc
// CMSC15100-2
// Winter 2005
// structure assignment
// getting data from the heap

#include <iostream>

using namespace std;

struct foo {
  int *a;
};

int main()
{
  // Declare variable of type struct account
  struct foo f,g;

  // point f's member to a new integer with no name
  // this is taken from the "heap"
  f.a = new int;

  *(f.a) = 6;

  // structure assignment -- copies the value of f.a (which is an
  // address) to the value of g.a.  So f.a and g.a point the same
  // place
  g = f;

  // edit the value pointed to in f.a
  *(f.a) = 4;

  cout << *(f.a) << endl;
  cout << *(g.a) << endl;  


  // now let's do a deep copy of f into g.
  // first grab a new integer from the heap
  g.a = new int;
  // assign values pointed to
  *(g.a) = *(f.a);

  // edit f.a
  *(f.a) = 14;

  cout << *(f.a) << endl;
  cout << *(g.a) << endl;

  cout << "addresses" << endl;
  cout << f.a << " " << g.a << endl;

  // return dynamically allocated integers to the heap
  delete f.a;
  delete g.a;

  return 0;
}
