You can also access a static member from a class object by using the class access operators . (dot) and -> (arrow). When a static member is accessed through a class access operator, the expression on the left of the . or -> operator is not evaluated.
Example of Accessing Static Members
A static member can be referred to independently of any association with a class object because there is only one static member shared by all objects of a class. A static member can exist even if no objects of its class have been declared.
When you access a static member, the expression that you use
to access it is not evaluated. In the following example, the
external function f( ) returns class type X. The function f() can
be used to access the static member i of class X. The function
f() itself is not called.
// This example shows that the expression used to // access a static member is not evaluated. class X { public: static int i; }; int X::i = 10; X f() { /* ... */ } void main () { int a; a = f().i; // f().i does not call f() }
Related Information