Hi I am trying to figure out why am I getting some compilation issue with my codes as below? After I tried incorporating class polygon into my line class it gave me a compilation error.
Compilation error:
main.cpp: In constructor ‘Line::Line()’:
main.cpp:55:28: error: no matching function for call to ‘Polygon::Polygon(int, int)’
Line() : p1(Polygon(0, 0)), p2(Polygon(0, 0)) {}
^
main.cpp:41:8: note: candidate: Polygon::Polygon()
class Polygon : public Shape
^~~~~~~
Right. Ok. Thanks repeater. So then how do I include my class point into my Polygon class? Not sure about how to do it... Or do I omit my class point and use class polygon instead. In short is class Point needed then?
I see that your class Point contains constructors you wrote:
1 2 3 4 5 6 7 8 9 10 11 12 13
class Point
{
private:
int x;
int y;
public:
Point() : x(0), y(0) {} // CONSTRUCTOR
Point(int x, int y) : x(x), y(y) {} // CONSTRUCTOR
public:
...
};
You just need to write a suitable constructor in Polygon.
In short is class Point needed then?
It's your code; you tell me. In the code above, your Polygon class contains a single Point object. Which you have named points; odd name, given that it is just one single Point.