I have a point class as such:
class Point {
int x, y;
public :
Point (int xx =0, int yy =0){ x = xx; y = yy ; } //constructor
int getX() const { return x;}
int getY() const { return y;}
void setX ( const int xx) { x = xx ;}
void setY ( const int yy) { y = yy ;}
};
Another class PointArray
class PointArray {
int size;
Point *points; etc...};
In another class Polygon, I have a PointArray Object.
How can user member initializer (in the class definition) to initialize the internal PointArray object of the Polygon.
struct Point {
int x=0, y=0;
};
struct PointArray : std::vector<Point>
{
using Base = std::vector<Point>;
using Base::Base; // make the constructor of std::vector availible in PointArray
};
struct Polygon {
PointArray points;
};
int main() {
Polygon p{ PointArray{Point{1,2}, Point{2,3}, Point{3,4}} };
}
Thank you for your reply. I think I'm supposed to use this inside the class definition.
Here are are the 2 member functions(below) in Polygon that I didn't include above.
I'm supposed to initialize the points inside the class.
public:
Polygon(PointArray ptarray[], int arrlength);
Polygon(Point mypoints[4],int arrlengh);