That's because you store the items of your CList
by value (your declaration is: CList <CShape, CShape> l;
). In that way, when you add elements to your list the copy-constructor of CShape
is called and copies only the data-members of CShape
.
You may want to use pointers instead . Something like:
CRectangle* r = new CRectangle(CPoint(0, 0), CPoint(1, 1), 255, 255, 255);
CList <CShape*> l;
l.AddHead(r);
Or, a shared_ptr. Something like:
std::shared_ptr<CRectangle> r(new CRectangle(CPoint(0, 0), CPoint(1, 1), 255, 255, 255));
CList <std::shared_ptr<CShape> > l;
l.AddHead(r);