July 2000
Intermediate to advanced
1280 pages
34h 55m
English
Many classes do not need constructors because class objects do not need default initialization. When the class designer does not add any constructors to the class, the system provides a default constructor (which does nothing) for the class.
class Cylinder { // OK if no constructors/destructors
double radius, height; // data is protected from client access
public:
void setCylinder(double r, double h); // methods are accessible
double getVolume();
void scaleCylinder(double factor);
void printCylinder();
} ; // end of class scope
All of the versions of class Cylinder that I discussed in the previous section were using the system-supplied default constructor. I did not mention it to avoid unnecessary complication of the discussion. ...
Read now
Unlock full access