The functions in this section
all return const pointers to Shape, or one of its derived
classes. Therefore, they must be invoked in such a way, that
the const qualifier is not discarded. See
the description of get_reg_polygon_ptr() below, for an example.
const virtual function: Shape* get_shape_ptr (const unsigned short shape_type, const unsigned short s)Copies one of the objects belonging to the
Solid, and returns a pointer toShapethat points to the copy. The object is found by dereferencing one of the pointers on one of the vectors of pointers belonging to theSolid. Currently, these vectors arecircles,ellipses,paths,rectangles, andreg_polygons. The argument shape_type specifies the vector, and the argument s specifies which element of the vector should be accessed. The followingpublic static constdata members ofSolidcan (and probably should) be passed as the shape_type argument:CIRCLE,ELLIPSE,PATH,RECTANGLE, andREG_POLYGON.This function was originally intended to be called within the more specialized functions in this section, namely:
get_circle_ptr(),get_ellipse_ptr(),get_path_ptr(),get_rectangle_ptr, andget_reg_polygon_ptr. However, these functions no longer useget_shape_ptr(), so this function is probably no longer needed.Icosahedron I(origin, 3); I.filldraw(); Reg_Polygon* t = static_cast<Reg_Polygon*>(I.get_shape_ptr(Solid::REG_POLYGON, 9)); t->fill(gray);
![]()
Fig. 184.
const virtual functions: const Reg_Polygon* get_circle_ptr (const unsigned short s)Each of these functions returns a pointer from one of the vectors of
Shapepointers belonging to theSolid. The argument s specifies which element of the appropriate vector should be returned. For example,get_reg_polygon_ptr(2)returns theReg_Polygon*inreg_polygons[2].Since these functions return
constpointers, they must be invoked in such a way, that theconstqualifier is not discarded, as noted at the beginning of this section. The following example demonstrates two ways of invokingget_reg_polygon_ptr():Dodecahedron d(origin, 3); d.draw(); const Reg_Polygon* ptr = d.get_reg_polygon_ptr(0); ptr->draw(black, "evenly scaled 4", "pencircle scaled 1mm"); Reg_Polygon A = *d.get_reg_polygon_ptr(5); A.fill(gray);
![]()
Fig. 185.