The Wayback Machine - https://web.archive.org/web/20120509162012/http://en.cppreference.com:80/w/cpp/language/static

static specifier

From cppreference.com
Jump to: navigation, search

Inside a class, declares members not bound to specific instances.

Contents

[edit] Syntax

static class_attribute
static class_method

[edit] Notes

  1. static attributes must be defined outside the class
  2. static constant integral attributes can be defined inline (until C++11)
  3. inside static methods there is no this pointer
  4. static methods cannot have other class-specific function specifier as cv, virtual or explicit overrides

[edit] See also

[edit] Example

struct C
{
    static void foo();
    static int n;
    static const int m = 16; // inline inizialization
};
 
int C::n = 0; // static attribute definition
 
void C::foo()
{
    // no reference to non-static members/methods can occur here
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox