I have a class CPolygon which is derived from the class CElement. [ I’m making use of polymorphism here].
class CElement : public CObject
{
public:
virtual ~CElement();
virtual void Draw(CDC* pDC){};
CPoint vertices[11];
protected:
CElement();
};
class CPolygon : public CElement
{
public:
CPolygon(CPoint mFirstPoint,CPoint mSecondPoint);
~CPolygon(void);
virtual void Draw(CDC* pDC);
protected:
CPoint mStartPoint;
CPoint mEndPoint;
CPolygon(void);
};
When I try to assign an array to the member vertices of a CElement object, I get the error: expression must be a modifiable Lvalue
CElement* a = new CPolygon(mFirstPoint,mSecondPoint);
a->vertices=vertices; //here!!
Why doesn’t this work??
Because
a->verticesis not a modifiable Lvalue… You can’t assign arrays in C++, you can only assign specific elements or do a copy.If you know the size to be
11, I’d use astd::array(orstd::vector, for flexibility) instead of a C-style array.