X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgeometry%2Fcompositeshape.h;h=55467d762993add17cbc4fe74ae7bfda2f776c22;hb=5e5a34537e5f2efc71181f2bf6878c3e2e62b398;hp=846607689df582a8a9f0ae46ae79c75eb832ed81;hpb=7353dc087872cdb93bd57cbaf2b6f0dcc21f9a03;p=libs%2Fmath.git diff --git a/source/geometry/compositeshape.h b/source/geometry/compositeshape.h index 8466076..55467d7 100644 --- a/source/geometry/compositeshape.h +++ b/source/geometry/compositeshape.h @@ -22,10 +22,10 @@ protected: CompositeShape() { } CompositeShape(const Shape &, const Shape &); - CompositeShape(const CompositeShape &); - CompositeShape &operator=(const CompositeShape &); template void init_from_iter_range(const Iter &, const Iter &); + CompositeShape(const CompositeShape &); + CompositeShape &operator=(const CompositeShape &); public: virtual ~CompositeShape(); @@ -55,11 +55,22 @@ inline void CompositeShape::init_from_iter_range(const Iter &begin, con } template -inline CompositeShape::CompositeShape(const CompositeShape &other) +inline CompositeShape::CompositeShape(const CompositeShape &other): + shapes(other.shapes) { - shapes.reserve(other.shapes.size()); - for(typename ShapeArray::const_iterator i=other.shapes.begin(); i!=other.shapes.end(); ++i) - shapes.push_back((*i)->clone()); + for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) + *i = (*i)->clone(); +} + +template +inline CompositeShape &CompositeShape::operator=(const CompositeShape &other) +{ + for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) + delete *i; + + shapes = other.shapes; + for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) + *i = (*i)->clone(); } template