Implementing Class Member Functions

We still have to create the second part of the class specification: providing code for those member functions represented by a prototype in the class declaration. Member function definitions are much like regular function definitions. Each has a function header and a function body. Member function definitions can have return types and arguments. But they also have two special characteristics:

• When you define a member function, you use the scope-resolution operator (::) to identify the class to which the function belongs.

• Class methods can access the private components of the class.

Let’s look at these points now.

First, the function header for a member function uses the scope-resolution operator (::) to ...

Get C++ Primer Plus 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.