Constructor of the base class should be called from the subclass's constructor's initializer list. That's what causing compiler error in your code. Also the below syntax is valid, but it just creates a temporary object of Polygon
and destoys it:
Polygon(APts);
From design point of view, by copying vectors by value you are doing expensive operations.
Just don't do it. Have a no argument constructor and then later populate the constructor.
class Polygon
{
public:
vector<Point*> pts; // can be made protected as well
Polygon() {};
};
class Triangle : public Polygon
{
public:
Triangle(Point* A, Point* B, Point* C)
{
pts.push_back(A); pts.push_back(B); pts.push_back(C);
}
};
If you have support for C++11, then the same code can be wrote more elegantly.
class Polygon {
protected:
vector<Point*> pts;
public:
Polygon(std::initializer_list<Point*>& v) : pts(v) {}
};
class Triangle : public Polygon {
public:
Triangle (Point* p1, Point* p2, Point* p3) :
Polygon({p1, p2, p3}) {}
};
class Square : public Polygon {
public:
Square (Point* p1, Point* p2, Point* p3, Point* p4) :
Polygon({p1, p2, p3, p4}) {}
};
Usage:
Triangle t({x, y, z});
Square s({w, x, y, z});