Implementing Member Functions Outside of Class

Notice that these member functions are correct only when they are implemented inside the class scope, that is, within the class braces, as in Listing 9.2. If they are implemented outside the class scope, different syntax should be used. This syntax is used when the relationship between member functions and data members of the class is established using function prototypes within the class declaration (specification) instead of the complete implementations, as in Listing 9.2.

 struct Cylinder { // start of class scope double radius, height; // data fields to access void setCylinder(double r, double h); // set Cylinder fields double getVolume(); // compute volume void scaleCylinder(double factor); ...

Get Core C++ A Software Engineering Approach 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.