O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required