unknown runtime error with classes

hello i wrote 2 classes and i can't understand why I cant use the copy constructor of class polynom.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

class Point
{

private:
	double x;
	double y;

public:
	Point(double a = 0, double b = 0)
	{
		x = a;
		y = b;
	}
	
	Point(Point const &p)
	{
		x = p.x;
		y = p.y;
	}

	Point& operator=(Point const &p)
	{
		if(this != &p)
		{
			x = p.x;
			y = p.y;
		}
		return *this;
	}

	void SetX(double a)
	{
		x = a;
	}

	void SetY(double b)
	{
		y = b;
	}

	double GetX()
	{
		return x;
	}

	double GetY()
	{
		return y;
	}

	void print()
	{
		cout << "(" << x << "," << y << ")"; 
	}
};

class Polygon
{
private:
	int vertexCount;
	Point **vertex;

public:
	Polygon(int vCount , Point **vx )
	{
		vertexCount = vCount;
		vertex = vx;
	}

	~Polygon()
	{
		delete [vertexCount] vertex; 
	}
	
	Polygon(Polygon const &p)
	{
		vertexCount = p.vertexCount;
		for(int i=0; i<vertexCount; i++)
			vertex[i] = p.vertex[i];
	}

	void print()
	{
		for(int i=0; i<vertexCount; i++)
		{
			vertex[i]->print();
			if(i<vertexCount-1)
				cout<< ", ";
		}	
	}
};

void main()
{
	Point *p1 = new Point(1,1);
	Point *p2 = new Point(2,2);
	Point *p3 = new Point(3,3);
	Point *p4 = new Point(4,4);


	Point **arrayPoint = new Point *[4];
	*arrayPoint = p1;
	*(arrayPoint+1) = p2;
	*(arrayPoint+2) = p3;
	*(arrayPoint+3) = p4;

	Point **arrayPoint2 = new Point *[3];
	*arrayPoint2 = p1;
	*(arrayPoint2+1) = p2;
	*(arrayPoint2+2) = p3;

	Polygon *pol1 = new Polygon(4, arrayPoint);
	Polygon *pol2 = new Polygon(*pol1);
	pol2->print();
}


its a runtime error when vertex[i] = p.vertex[i]; in copy constructor. Thanks!
Last edited on
sry for stupid question i found the error ... I didn't create the array vertex = new Point *[vertexCount];
Topic archived. No new replies allowed.