Class constructor compilation error

I am receiving a compilation error which I am quite vexed about at this point for my polygon constructor(Refer below). I would appreciate if anyone could help me. Thank you.

Compilation error:

no matching function for call to ‘Object::PointType::PointType()’
Polygon::PointType* vertices = new Polygon::PointType[max_index];

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
class Object
{
public:

private:
	float d;

public:
	Object(float n) : d(n){}
 
	float depth() const
	{
		return d;
	}
 
struct PointType
{
	float x;
	float y;
	 
};
};
class Point :public Object
 
private:
    PointType mpoint;
	
public:

    Point(const PointType& pt, float& y1) : mpoint(pt), Object(y1) {}
};
class Polygon :  public Point
{
private:
	Object::PointType *mpt;
	int msize;

public:
 	  
	int size()
	{
		return msize;
	}

 };

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

const float EPSILON = 1e-5f;

bool is_near(float x, float y)
{
	return std::abs(x - y) < EPSILON;
}

float frand()
{
	return 10.0f * float(rand()) / float(RAND_MAX);
}

int main()
{
	srand(unsigned(time(0)));
	int count = 0;
	int max_count = 0;

	int max_index = 3 + rand() % 8;
	float* xs = new float[max_index];
	float* ys = new float[max_index];
	float depth = frand();
	float x = 0;
	float y = 0;
	Polygon::PointType* vertices = new Polygon:: PointType[max_index];
	for (int index = 0; index < max_index; ++index)
	{
		xs[index] = frand();
		ys[index] = frand();
		vertices[index] = Polygon::PointType(xs[index], ys[index]);
		x += xs[index];
		y += ys[index];
		y += ys[index];
	}
	x /= static_cast<float>(max_index);
	y /= static_cast<float>(max_index);
	Polygon polygon(vertices, max_index, depth);
	delete[] vertices;
	if (polygon.size() == max_index)
	{
		++count;
	}
	else
	{
		std::cout << "  - Polygon::size test failed" << std::endl;
	}
	++max_count;
}
Last edited on
new Polygon::PointType[max_index];

This is an attempt to create an an array of Polygon::PointType objects.

Each of those will be created using the default constructor, which would be of form ‘PointType()’

But the default constructor for them does not exist (because you didn't provide one, and you don't get one for free because you did provide at least one other constructor).

You can't use a constructor that doesn't exist.
Topic archived. No new replies allowed.