template <class C> C* create_new (const C* arg)template <class C> C* create_new (const C& arg)These functions dynamically allocate an object derived from
Shapeon the free store, returning a pointer to the type of theShapeand settingon_free_storetotrue.If a non-zero pointer or a reference is passed to
create_new(), the new object will be a copy of arg.It is not possible to instantiate more than one specialization of
create_new()that takes no argument, because calls to these functions would be ambiguous. If the new object is not meant to be a copy of an existing one, ‘0’ must be passed tocreate_new()as its argument.
create_newis called like this:Point* p = create_new<Point>(0); p->show("*p:"); -| *p: (0, 0, 0) Color c(.3, .5, .25); Color* d = create_new<Color>(c); d->show("*d:"); -| *d: name == use_name == 0 red_part == 0.3 green_part == 0.5 blue_part == 0.25 Point a0(3, 2.5, 6); Point a1(10, 11, 14); Path q(a0, a1); Path* r = create_new<Path>(&q); r->show("*r:"); -| *r: points.size() == 2 connectors.size() == 1 (3, 2.5, 6) -- (10, 11, 14);Specializations of this template function are currently declared for
Color,Point,Path,Reg_Polygon,Rectangle,Ellipse,Circle,Solid, andCuboid.