Saturday, 23 June 2012

What is a static member of a class?

Class members can be either data members or methods.
Static data member:
- shared among all instances of the class
- is created even if no instances of the class exist. There is always only a single instance of the static data member!
- its declaration (in the class scope) is NOT a definition at the same time! Therefore in has to be defined in a file scope.
- has external linkage
- requires scope operator in order to be accessed

Static method:
- can be called if there are no instances of the class
- can access only static data members
- requires scope operator in order to be called

Static Data Members (MSDN)

No comments:

Post a Comment