or
"cpp/language/constructor")  
[ Default member initializer
](/w/cpp/language/data_members#Member_initialization "cpp/language/data
members") (C++11)  
[ ` friend ` specifier ](/w/cpp/language/friend "cpp/language/friend")  
[ ` explicit ` specifier ](/w/cpp/language/explicit "cpp/language/explicit")  
[ Converting constructor ](/w/cpp/language/converting_constructor
"cpp/language/converting constructor")  
Special member functions  
[ Default constructor ](/w/cpp/language/default_constructor
"cpp/language/default constructor")  
[ Copy constructor ](/w/cpp/language/copy_constructor "cpp/language/copy
constructor")  
[ Move constructor ](/w/cpp/language/move_constructor "cpp/language/move
constructor") (C++11)  
[ Copy assignment operator ](/w/cpp/language/copy_assignment
"cpp/language/copy assignment")  
[ Move assignment operator ](/w/cpp/language/move_assignment
"cpp/language/move assignment") (C++11)  
[ Destructor ](/w/cpp/language/destructor "cpp/language/destructor")  
Inheritance  
[ Base and derived classes ](/w/cpp/language/derived_class
"cpp/language/derived class")  
[ Empty base optimization (EBO) ](/w/cpp/language/ebo "cpp/language/ebo")  
[ Virtual member functions ](/w/cpp/language/virtual "cpp/language/virtual")  
[ Pure virtual functions and abstract classes ](/w/cpp/language/abstract_class
"cpp/language/abstract class")  
[ ` override ` specifier ](/w/cpp/language/override "cpp/language/override")
(C++11)  
[ ` final ` specifier ](/w/cpp/language/final "cpp/language/final") (C++11)  
  
[ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/language/classes/navbar_content&action=edit)

Inside a class definition, the keyword [ ` static ` ](/w/cpp/keywords/static
"cpp/keywords/static") declares members that are not bound to class instances.

Outside a class definition, it has a different meaning: see [ storage duration
](/w/cpp/language/storage_duration "cpp/language/storage duration") .

##  Contents

  * 1  Syntax 
  * 2  Explanation 
    * 2.1  Static member functions 
    * 2.2  Static data members 
    * 2.3  Constant static members 
  * 3  Defect reports 
  * 4  References 
  * 5  See also 

  
---  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/language/static&action=edit&section=1 "Edit
section: Syntax") ]  Syntax

A declaration for a static member is a [ member declaration
](/w/cpp/language/class#Member_specification "cpp/language/class") whose
declaration specifiers contain the keyword  static  . The keyword  static
usually appears before other specifiers (which is why the syntax is often
informally described as  static  data-member  or  static  member-function  ),
but may appear anywhere in the specifier sequence.

The name of any static data member and static member function must be
different from the name of the containing class.

###  [ [ edit
](/mwiki/index.php?title=cpp/language/static&action=edit&section=2 "Edit
section: Explanation") ]  Explanation

Static members of a class are not associated with the objects of the class:
they are independent variables with [ static  or thread  (since C++11)
storage duration ](/w/cpp/language/storage_duration "cpp/language/storage
duration") or regular functions.

The  static  keyword is only used with the declaration of a static member,
inside the class definition, but not with the definition of that static
member:

    
    
    class X { static int n; }; // declaration (uses 'static')
    int X::n = 1;              // definition (does not use 'static')

The declaration inside the class body is not a definition and may declare the
member to be of [ incomplete type ](/w/cpp/language/incomplete_type
"cpp/language/incomplete type") (other than  void  ), including the type in
which the member is declared:

    
    
    struct Foo;
     
    struct S
    {
        static int a[]; // declaration, incomplete type
        static Foo x;   // declaration, incomplete type
        static S s;     // declaration, incomplete type (inside its own d