July 2013
Intermediate to advanced
124 pages
1h 42m
English
CHAPTER 17
![]()
Static
The static keyword is used to create class members that exist in only one copy, which belongs to the class itself. These members are shared among all instances of the class. This is different from instance (non-static) members, which are created as new copies for each new object.
Static fields
A static field (class field) cannot be initialized inside the class like an instance field. Instead it must be defined outside of the class declaration. This initialization will only take place once, and the static field will then remain initialized throughout the life of the application.
class MyCircle{ public: double r; // ...
Read now
Unlock full access