Using Default Values

Just as non-class functions can have one or more default values, so can each member function of a class. The same rules apply for declaring the default values, as illustrated in Listing 13.2.

Listing 13.2. Using Default Values
 0: //Listing 13.2 Default values in member functions 1: #include <iostream> 2: 3: // Rectangle class declaration 4: class Rectangle 5: { 6: public: 7: // constructors 8: Rectangle(int width, int height); 9: ~Rectangle(){} 10: void DrawShape(int aWidth, int aHeight 11: bool UseCurrentVals = false) const; 12: private: 13: int itsWidth; 14: int itsHeight; 15: }; 16: 17: //Constructor implementation 18: Rectangle::Rectangle(int width, int height): 19: itsWidth(width), // initializations 20: itsHeight(height) ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.