#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream.h>

class classVec2d_3{

  //make the constructor classVec2d_s() public
  //make the copy constructor classVec2d_s() public
  //make the destructor -classVec2d_s() public
public:
  classVec2d_3();
  classVec2d_3(const classVec2d_3& myClass);
  ~classVec2d_3();
  float x;
  float y;

private:
  static int count;
};  

//Make the constructor
classVec2d_3::classVec2d_3() :
  x(5.0f),y(6.0f)
{
  std::cout << "Constructing : now "
	    << ++(this->count) << " classVec2d_3 object exist\n";
}
//Make the destructor
classVec2d_3::~classVec2d_3() 
{
  std::cout << "Destructing : now "
	    << --(this->count) << " classVec2d_3 object exist\n";
}
//Make a copy constructor
classVec2d_3::classVec2d_3(const classVec2d_3& thing)
{
  //this->x = thing.x;
  //this->y = thing.y;
  x = thing.x;
  y = thing.y;
  std::cout << "Constructing : now "
            << ++(this->count) << " classVec2d_3 object exist\n";
}

//!!!!!!MUST DEFINE THE COUNT!!!!!!!			  

int classVec2d_3::count = 0;



int main()
{
  class testClass {};
  //Here is a structure
  struct structVec2d{
    float x;
    float y;
  };
  structVec2d aVec;
  aVec.x = 2;
  aVec.y = 3;
  cout << "aVec = "<<aVec.x<<" "<<aVec.y<<"\n";


  //Here is a class
  class classVec2d_1{
    float x;
    float y;
  };
  classVec2d_1 classVec_1;
  // NOTE: the statements below will NOT compile
  //-------------------------------
  //classVec_1.x = 2;
  //classVec_1.y = 3;
  //cout << "classVec_1 = "<<classVec_1.x<<" "<<classVec_1.y<<"\n";
  //-------------------------------
  //This is because the default behavior for a class is
  //to have private access

  //We can make the access public as shown below
  class classVec2d_2{
  public:
    float x;
    float y;
  };
  classVec2d_2 classVec_2;
  classVec_2.x = 2;
  classVec_2.y = 3;
  cout << "classVec_2 = "<<classVec_2.x<<" "<<classVec_2.y<<"\n";

  //To make a pointer to a class and access the members using "->"
  classVec2d_2 *classVec_2Ptr = new classVec2d_2;
  classVec_2Ptr->x = 4;
  classVec_2Ptr->y = 5;
  cout << "*classVec_2Ptr = "<<classVec_2Ptr->x<<" "<<classVec_2Ptr->y<<"\n";

 
  //Calling a "constuctor" using the "new" command 
  cout<<"constructing\n";
  classVec2d_3 *ptr1 = new classVec2d_3;
  classVec2d_3 *ptr2 = new classVec2d_3;
  classVec2d_3 *ptr3 = new classVec2d_3;
  classVec2d_3 *ptr4 = new classVec2d_3;
  
  //Print out the variable x
  cout<<"\n ptr1->x = "<< ptr1->x <<"\n";
  
  ptr1->x = 99.0;
  cout<<"\n ptr1->x = "<< ptr1->x <<"\n";
  
  cout<<"\n";

  //Make a copy  
  //  classVec2d_3 pt1(1.0f, 2.0f);
  classVec2d_3 copyOfThing1(*ptr1);   
  cout<<"\n copyOfThing1->x = "<< copyOfThing1.x <<"\n\n";

  //Calling a "destuctor" using the "delete" command 
  cout<<"destructing\n";
  delete ptr1;
  delete ptr2;
  delete ptr3;
  delete ptr4;

}




