... subtle reasons that you’ll learn in Section 10.13. For now, just declare all single-parameter constructors explicit. Line 8 of Fig. 3.4 does not specify a return type, because constructors cannot return values—not even void. Also, constructors cannot be declared const (because initializing an object modifies it).

Using the Same Parameter Name in the Constructor and Member Function setName

Recall from Section 3.3.4 that member function parameters are local variables. In Fig. 3.4, the constructor and member function setName both have a parameter called accountName. Though their identifiers are identical, the parameter in line 8 is a local variable of the constructor that’s not visible to member function setName. Similarly, the parameter in line 14 ...

Get C++ How to Program, 10/e 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.