This is my program:
#include <iostream>
using namespace std;
class Point
{
private: int x, y;
public:
Point(int f = 0, int g = 0)
{
x = f;
y = g;
}
int getX() const
{
return x;
}
int getY() const
{
return y;
}
void setX(const int new_x)
{
x = new_x;
}
void setY(const int new_y)
{
y = new_y;
}
};
class PointArray
{
private:
Point * loc;
int len;
public:
PointArray()
{
len = 0;
loc = new Point[0];
}
PointArray(const Point * points, const int size)
{
len = size;
loc = new Point[len];
for(int f = 0; f < len; f++)
loc[f] = points[f];
}
PointArray(const PointArray& pv)
{
len = pv.len;
loc = new Point[len];
for(int f = 0; f < len; f++)
loc[f] = pv.loc[f];
}
~PointArray()
{
delete[] loc;
}
void resize(int n)
{
Point *loc1 = new Point[n];
for(int f = 0; f < len && f < n; f++)
loc1[f] = loc[f];
len = n;
delete[] loc;
loc = loc1;
}
void pushBack(const Point &p)
{
resize(len+1);
loc[len-1] = p;
}
void insert(const int pos, const Point &p)
{
resize(len+1);
for(int f = len-1; f > pos; f--)
loc[f] = loc[f-1];
loc[pos] = p;
}
void remove(const int pos)
{
for(int f = pos; f < len-1; f++)
loc[f] = loc[f+1];
resize(len-1);
}
const int getSize() const
{
return len;
}
void clear()
{
resize(0);
}
Point * get(const int pos)
{
if (pos >= len)
return NULL;
else
{
Point * x = new Point();
*x = loc[pos];
return x;
}
}
const Point * get(const int pos) const
{
if (pos >= len)
return NULL;
else
{
Point * x = new Point();
*x = loc[pos];
return x;
}
}
};
class Polygon
{
protected:
PointArray * loci;
int sides;
static int N;
public:
Polygon(Point * loc, int len)
{
loci = new PointArray(loc, len);
sides = len;
N++;
}
Polygon(const PointArray& pv)
{
loci = new PointArray(pv);
sides = pv.getSize();
N++;
}
Polygon(const Polygon& pv)
{
loci = new PointArray(*pv.loci);
sides = pv.sides;
N++;
}
~Polygon()
{
delete loci;
N--;
}
virtual double area() = 0;
static int getNumPolygons()
{
return N;
}
int getNumSides()
{
return sides;
}
const PointArray * getPoints()
{
return loci;
}
};
class Rectangle : public Polygon
{
private:
typedef Polygon super;
void makeRectangle(const Point e, const Point r)
{
Point * loci = new Point[4];
loci[0] = e;
loci[2] = r;
loci[1] = new Point(e.getX(), r.getY());
loci[3] = new Point(r.getX(), e.getY());
}
void makeRectangle (const int x1, const int x2, const int y1, const int y2)
{
Point * loci = new Point[4];
loci[0] = new Point(x1, y1);
loci[1] = new Point(x2, y1);
loci[2] = new Point(x2, y2);
loci[3] = new Point(x1, y2);
}
};
The compiler is giving me these errors in the two overloaded makeRectangle() when they call the Point(int, int) constructor, saying:
geometry.cpp: In member function 'void Rectangle::makeRectangle(Point, Point)':
geometry.cpp:170:45: error: invalid conversion from 'Point*' to 'int' [-fpermissive]
geometry.cpp:8:4: error: initializing argument 1 of 'Point::Point(int, int)' [-fpermissive]
geometry.cpp:171:45: error: invalid conversion from 'Point*' to 'int' [-fpermissive]
geometry.cpp:8:4: error: initializing argument 1 of 'Point::Point(int, int)' [-fpermissive]
geometry.cpp: In member function 'void Rectangle::makeRectangle(int, int, int, int)':
geometry.cpp:176:33: error: invalid conversion from 'Point*' to 'int' [-fpermissive]
geometry.cpp:8:4: error: initializing argument 1 of 'Point::Point(int, int)' [-fpermissive]
geometry.cpp:177:33: error: invalid conversion from 'Point*' to 'int' [-fpermissive]
geometry.cpp:8:4: error: initializing argument 1 of 'Point::Point(int, int)' [-fpermissive]
geometry.cpp:178:33: error: invalid conversion from 'Point*' to 'int' [-fpermissive]
geometry.cpp:8:4: error: initializing argument 1 of 'Point::Point(int, int)' [-fpermissive]
geometry.cpp:179:33: error: invalid conversion from 'Point*' to 'int' [-fpermissive]
geometry.cpp:8:4: error: initializing argument 1 of 'Point::Point(int, int)' [-fpermissive]
Because x1, x2, y1, and y2 are integers and therefore should be compatible with the Point(int, int) constructor, I do not understand why it is giving me the error: "invalid conversion from 'Point*' to 'int'".