Q&A

Q1:Why use static data when you can use global data?
A1: Static data is scoped to the class. It therefore is available only through an object of the class—through an explicit and full call using the class name if the data are public, or by using a static member function. Static data is typed to the class type, however, and the restricted access and strong typing makes static data safer than global data.
Q2:Why use static member functions when you can use global functions?
A2: Static member functions are scoped to the class, and can be called only by using an object of the class or an explicit full specification (such as ClassName::FunctionName()).
Q3:Why not make all classes friends of all the classes they use?
A3: Making one class a friend ...

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.