Website Summary Files Commits Branches @commit @diff @stats
path: root / Polymorphism / Shapes / Shape.cpp
blob: 075110848502d608f907502b5215bd9f37a92611 (plain) (blame)
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
#include "Shape.h"

Shape::Shape(int pointsCount)
{
	points = new Point[pointsCount];
	this->pointsCount = pointsCount;
}

void Shape::setPoint(int x, int y, int ind)
{
	Point current(x, y);
	points[ind] = current;
		
}

const Point& Shape::getPoint(int ind)
{
	return points[ind];
}

void Shape::CopyFrom(const Shape& other)
{
	points = new Point[other.pointsCount];
	pointsCount = other.pointsCount;

	for (int i = 0; i < pointsCount; i++)
		points[i] = other.points[i];
}
void Shape::Free()
{
	delete[] points;
	pointsCount = 0;
}
Shape::Shape(const Shape& other)
{
	CopyFrom(other);
}
Shape& Shape::operator=(const Shape& other)
{
	if (this != &other)
	{
		Free();
		CopyFrom(other);
	}
	return *this;
}
Shape::~Shape()
{
	Free();
}