Declaring static Members
We say a member is associated with the class by adding the keyword static to its declaration. Like any other member, static members can be public or private. The type of a static data member can be const, reference, array, class type, and so forth.
As an example, we’ll define a class to represent an account record at a bank:
class Account {public: void calculate() { amount += amount * interestRate; } static double rate() { return interestRate; } static void rate(double);private: std::string owner; double amount; static double interestRate; static double initRate();};
The static members of a class exist outside any object. Objects do not contain data associated with static data members. Thus, each ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access