October 1997
Intermediate to advanced
800 pages
20h 48m
English
A function may use a local class to create objects that it needs. Local classes are similar to nested classes, except that local class definitions appear inside blocks and functions. The following function, for instance, creates Circle objects with a local class.
enum color { red, green, blue }; // enumeration bool bright = true; // global variable void make_circle(double rad, color c) { static bool visible = true; // static variable bool bright = true; // local variable class Circle { // local class private: double radius; color cn; bool visibility; bool contrast; public: Circle(double r, color hue, bool vis = false, bool con = false) { radius = r; cn = hue; visibility = vis; contrast = con; } void appearance() { visibility ...