| Refresh | Home EGTry.com


//copy constructor
#include <stdio.h>

class Point
{
  int x, y;
  public:
    Point( const Point& p1);
    Point(int,int);
    int getX();
    int getY();
};

Point::Point(int a, int b)
{
  printf("constructor\n");
  x=a;
  y=b;
}

Point::Point(const Point& p1)
{
  printf("copy constructor\n");
  x=p1.x;
  y=p1.y;
}


int
Point::getX()
{
  return x;
}

int Point::getY()
{
  return y;
}

int main()
{
  Point p(2,3);
  Point p2(p);

  printf("x=%d\n", p.getX());
  printf("point 2 x=%d\n", p2.getX());

}