[class.mem.general] # 11 Classes [[class]](./#class) ## 11.4 Class members [[class.mem]](class.mem#general) ### 11.4.1 General [class.mem.general] [member-specification:](#nt:member-specification "11.4.1 General [class.mem.general]") [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]") [*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]")opt [*access-specifier*](class.derived.general#nt:access-specifier "11.7.1 General [class.derived.general]") : [*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]")opt [member-declaration:](#nt:member-declaration "11.4.1 General [class.mem.general]") [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")opt [*member-declarator-list*](#nt:member-declarator-list "11.4.1 General [class.mem.general]")opt ; [*function-definition*](dcl.fct.def.general#nt:function-definition "9.6.1 General [dcl.fct.def.general]") [*friend-type-declaration*](#nt:friend-type-declaration "11.4.1 General [class.mem.general]") [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]") [*using-enum-declaration*](enum.udecl#nt:using-enum-declaration "9.8.2 The using enum declaration [enum.udecl]") [*static_assert-declaration*](dcl.pre#nt:static_assert-declaration "9.1 Preamble [dcl.pre]") [*consteval-block-declaration*](dcl.pre#nt:consteval-block-declaration "9.1 Preamble [dcl.pre]") [*template-declaration*](temp.pre#nt:template-declaration "13.1 Preamble [temp.pre]") [*explicit-specialization*](temp.expl.spec#nt:explicit-specialization "13.9.4 Explicit specialization [temp.expl.spec]") [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]") [*alias-declaration*](dcl.pre#nt:alias-declaration "9.1 Preamble [dcl.pre]") [*opaque-enum-declaration*](dcl.enum#nt:opaque-enum-declaration "9.8.1 Enumeration declarations [dcl.enum]") [*empty-declaration*](dcl.pre#nt:empty-declaration "9.1 Preamble [dcl.pre]") [member-declarator-list:](#nt:member-declarator-list "11.4.1 General [class.mem.general]") [*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]") [*member-declarator-list*](#nt:member-declarator-list "11.4.1 General [class.mem.general]") , [*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]") [member-declarator:](#nt:member-declarator "11.4.1 General [class.mem.general]") [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") [*virt-specifier-seq*](#nt:virt-specifier-seq "11.4.1 General [class.mem.general]")opt [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1 General [dcl.contract.func]")opt [*pure-specifier*](#nt:pure-specifier "11.4.1 General [class.mem.general]")opt [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]") [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1 General [dcl.contract.func]")opt [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]") [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt : [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]") [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")opt [virt-specifier-seq:](#nt:virt-specifier-seq "11.4.1 General [class.mem.general]") [*virt-specifier*](#nt:virt-specifier "11.4.1 General [class.mem.general]") [*virt-specifier-seq*](#nt:virt-specifier-seq "11.4.1 General [class.mem.general]")opt [virt-specifier:](#nt:virt-specifier "11.4.1 General [class.mem.general]") override final [pure-specifier:](#nt:pure-specifier "11.4.1 General [class.mem.general]") = 0 [friend-type-declaration:](#nt:friend-type-declaration "11.4.1 General [class.mem.general]") friend [*friend-type-specifier-list*](#nt:friend-type-specifier-list "11.4.1 General [class.mem.general]") ; [friend-type-specifier-list:](#nt:friend-type-specifier-list "11.4.1 General [class.mem.general]") [*friend-type-specifier*](#nt:friend-type-specifier "11.4.1 General [class.mem.general]") ...opt [*friend-type-specifier-list*](#nt:friend-type-specifier-list "11.4.1 General [class.mem.general]") , [*friend-type-specifier*](#nt:friend-type-specifier "11.4.1 General [class.mem.general]") ...opt [friend-type-specifier:](#nt:friend-type-specifier "11.4.1 General [class.mem.general]") [*simple-type-specifier*](dcl.type.simple#nt:simple-type-specifier "9.2.9.3 Simple type specifiers [dcl.type.simple]") [*elaborated-type-specifier*](dcl.type.elab#nt:elaborated-type-specifier "9.2.9.5 Elaborated type specifiers [dcl.type.elab]") [*typename-specifier*](temp.res.general#nt:typename-specifier "13.8.1 General [temp.res.general]") [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L616) In the absence of a [*virt-specifier-seq*](#nt:virt-specifier-seq "11.4.1 General [class.mem.general]"), the token sequence = 0 is treated as a [*pure-specifier*](#nt:pure-specifier "11.4.1 General [class.mem.general]") if the type of the [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1 General [dcl.decl.general]") ([[dcl.meaning.general]](dcl.meaning.general "9.3.4.1 General")) is a function type, and is otherwise treated as a [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")[.](#1.sentence-1) [*Note [1](#note-1)*: If the member declaration acquires a function type through template instantiation, the program is ill-formed; see [[temp.spec.general]](temp.spec.general "13.9.1 General")[.](#1.sentence-2) — *end note*] [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L628) The optional [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1 General [dcl.contract.func]") ([[dcl.contract.func]](dcl.contract.func "9.4.1 General")) in a [*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]") shall be present only if the [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") declares a function[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L634) The [*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]") in a class definition declares the full set of members of the class; no member can be added elsewhere[.](#3.sentence-1) A [*direct member*](#def:member,direct "11.4.1 General [class.mem.general]") of a class X is a member of X that was first declared within the [*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]") of X, including anonymous union members ([[class.union.anon]](class.union.anon "11.5.2 Anonymous unions")) and direct members thereof[.](#3.sentence-2) Members of a class are data members, member functions ([[class.mfct]](class.mfct "11.4.2 Member functions")), nested types, enumerators, and member templates ([[temp.mem]](temp.mem "13.7.3 Member templates")) and specializations thereof[.](#3.sentence-3) [*Note [2](#note-2)*: A specialization of a static data member template is a static data member[.](#3.sentence-4) A specialization of a member function template is a member function[.](#3.sentence-5) A specialization of a member class template is a nested class[.](#3.sentence-6) — *end note*] [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L650) A [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]") does not itself declare new members of the class if it is - [(4.1)](#4.1) a friend declaration ([[class.friend]](class.friend "11.8.4 Friends")), - [(4.2)](#4.2) a [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]") ([[temp.deduct.guide]](temp.deduct.guide "13.7.2.3 Deduction guides")), - [(4.3)](#4.3) a [*template-declaration*](temp.pre#nt:template-declaration "13.1 Preamble [temp.pre]") whose [*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]") is one of the above, - [(4.4)](#4.4) a [*static_assert-declaration*](dcl.pre#nt:static_assert-declaration "9.1 Preamble [dcl.pre]"), - [(4.5)](#4.5) a [*consteval-block-declaration*](dcl.pre#nt:consteval-block-declaration "9.1 Preamble [dcl.pre]"), - [(4.6)](#4.6) a [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]") ([[namespace.udecl]](namespace.udecl "9.10 The using declaration")), or - [(4.7)](#4.7) an [*empty-declaration*](dcl.pre#nt:empty-declaration "9.1 Preamble [dcl.pre]")[.](#4.sentence-1) For any other [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]"), each declared entity that is not an [unnamed bit-field](class.bit#def:bit-field,unnamed "11.4.10 Bit-fields [class.bit]") is a member of the class, and each such [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]") shall either declare at least one member name of the class or declare at least one unnamed bit-field[.](#4.sentence-2) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L671) A [*data member*](#def:data_member "11.4.1 General [class.mem.general]") is a non-function member introduced by a[*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]")[.](#5.sentence-1) A [*member function*](#def:member_function "11.4.1 General [class.mem.general]") is a member that is a function[.](#5.sentence-2) Nested types are classes ([[class.name]](class.name "11.3 Class names"), [[class.nest]](class.nest "11.4.12 Nested class declarations")) and enumerations ([[dcl.enum]](dcl.enum "9.8.1 Enumeration declarations")) declared in the class and arbitrary types declared as members by use of a typedef declaration ([[dcl.typedef]](dcl.typedef "9.2.4 The typedef specifier")) or [*alias-declaration*](dcl.pre#nt:alias-declaration "9.1 Preamble [dcl.pre]")[.](#5.sentence-3) The enumerators of an [unscoped enumeration](dcl.enum "9.8.1 Enumeration declarations [dcl.enum]") defined in the class are members of the class[.](#5.sentence-4) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L682) A data member or member function may be declared static in its [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]"), in which case it is a [*static member*](#def:member,static "11.4.1 General [class.mem.general]") (see [[class.static]](class.static "11.4.9 Static members")) (a [*static data member*](#def:data_member,static "11.4.1 General [class.mem.general]") ([[class.static.data]](class.static.data "11.4.9.3 Static data members")) or[*static member function*](#def:member_function,static "11.4.1 General [class.mem.general]") ([[class.static.mfct]](class.static.mfct "11.4.9.2 Static member functions")), respectively) of the class[.](#6.sentence-1) Any other data member or member function is a [*non-static member*](#def:member,non-static "11.4.1 General [class.mem.general]") (a [*non-static data member*](#def:data_member,non-static "11.4.1 General [class.mem.general]") or[*non-static member function*](#def:member_function,non-static "11.4.1 General [class.mem.general]") ([[class.mfct.non.static]](class.mfct.non.static "11.4.3 Non-static member functions")), respectively)[.](#6.sentence-2) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L693) Every object of class type has a unique member subobject corresponding to each of its direct non-static data members[.](#7.sentence-1) If any non-static data member of a class C is of reference type, then let D be an invented class that is identical to C except that each non-static member of D corresponding to a member of C of type “reference to T” instead has type “pointer to T”[.](#7.sentence-2) Every member subobject of a complete object of type C has the same size, alignment, and offset as that of the corresponding subobject of a complete object of type D[.](#7.sentence-3) The size and alignment of C are the same as the size and alignment of D[.](#7.sentence-4) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L708) A member shall not be declared twice in the[*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]"), except that - [(8.1)](#8.1) a nested class or member class template can be declared and then later defined, and - [(8.2)](#8.2) an enumeration can be introduced with an [*opaque-enum-declaration*](dcl.enum#nt:opaque-enum-declaration "9.8.1 Enumeration declarations [dcl.enum]") and later redeclared with an [*enum-specifier*](dcl.enum#nt:enum-specifier "9.8.1 Enumeration declarations [dcl.enum]")[.](#8.sentence-1) [*Note [3](#note-3)*: A single name can denote several member functions provided their types are sufficiently different ([[basic.scope.scope]](basic.scope.scope "6.4.1 General"))[.](#8.sentence-2) — *end note*] [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L723) A redeclaration of a class member outside its class definition shall be a definition, an explicit specialization, or an explicit instantiation ([[temp.expl.spec]](temp.expl.spec "13.9.4 Explicit specialization"), [[temp.explicit]](temp.explicit "13.9.3 Explicit instantiation"))[.](#9.sentence-1) The member shall not be a non-static data member[.](#9.sentence-2) [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L730) A [*complete-class context*](#def:complete-class_context "11.4.1 General [class.mem.general]") of a class (template) is a - [(10.1)](#10.1) function body ([[dcl.fct.def.general]](dcl.fct.def.general "9.6.1 General")), - [(10.2)](#10.2) default argument ([[dcl.fct.default]](dcl.fct.default "9.3.4.7 Default arguments")), - [(10.3)](#10.3) default template argument ([[temp.param]](temp.param "13.2 Template parameters")), - [(10.4)](#10.4) [*noexcept-specifier*](except.spec#nt:noexcept-specifier "14.5 Exception specifications [except.spec]") ([[except.spec]](except.spec "14.5 Exception specifications")), - [(10.5)](#10.5) [*function-contract-specifier*](dcl.contract.func#nt:function-contract-specifier "9.4.1 General [dcl.contract.func]") ([[dcl.contract.func]](dcl.contract.func "9.4.1 General")), or - [(10.6)](#10.6) default member initializer within the [*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]") of the class or class template[.](#10.sentence-1) [*Note [4](#note-4)*: A complete-class context of a nested class is also a complete-class context of any enclosing class, if the nested class is defined within the [*member-specification*](#nt:member-specification "11.4.1 General [class.mem.general]") of the enclosing class[.](#10.sentence-2) — *end note*] [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L748) A class C is complete at a program point P if the definition of C is reachable from P ([[module.reach]](module.reach "10.7 Reachability")) or if P is in a complete-class context of C[.](#11.sentence-1) Otherwise, C is incomplete at P[.](#11.sentence-2) [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L754) If a [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]") matches the syntactic requirements of [*friend-type-declaration*](#nt:friend-type-declaration "11.4.1 General [class.mem.general]"), it is a [*friend-type-declaration*](#nt:friend-type-declaration "11.4.1 General [class.mem.general]")[.](#12.sentence-1) [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L759) In a [*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]"), an = immediately following the [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") is interpreted as introducing a [*pure-specifier*](#nt:pure-specifier "11.4.1 General [class.mem.general]") if the [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1 General [dcl.decl.general]") has function type, otherwise it is interpreted as introducing a [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")[.](#13.sentence-1) [*Example [1](#example-1)*: struct S {using T = void(); T * p = 0; // OK, [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")virtual T f = 0; // OK, [*pure-specifier*](#nt:pure-specifier "11.4.1 General [class.mem.general]")}; — *end example*] [14](#14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L776) In a [*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]") for a bit-field, the [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]") is parsed as the longest sequence of tokens that could syntactically form a [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]")[.](#14.sentence-1) [*Example [2](#example-2)*: int a;const int b = 0;struct S {int x1 : 8 = 42; // OK, "= 42" is [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")int x2 : 8 { 42 }; // OK, "{ 42 }" is [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")int y1 : true ? 8 : a = 42; // OK, [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]") is absentint y2 : true ? 8 : b = 42; // error: cannot assign to const intint y3 : (true ? 8 : b) = 42; // OK, "= 42" is [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]")int z : 1 || new int { 0 }; // OK, [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]") is absent}; — *end example*] [15](#15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L796) A [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]") shall appear only in the declaration of a data member[.](#15.sentence-1) (For static data members, see [[class.static.data]](class.static.data "11.4.9.3 Static data members"); for non-static data members, see [[class.base.init]](class.base.init "11.9.3 Initializing bases and members") and [[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates"))[.](#15.sentence-2) A [*brace-or-equal-initializer*](dcl.init.general#nt:brace-or-equal-initializer "9.5.1 General [dcl.init.general]") for a non-static data memberspecifies a [*default member initializer*](#def:default_member_initializer "11.4.1 General [class.mem.general]") for the member, and shall not directly or indirectly cause the implicit definition of a defaulted default constructor for the enclosing class or the exception specification of that constructor[.](#15.sentence-3) An immediate invocation ([[expr.const]](expr.const "7.7 Constant expressions")) that is a potentially-evaluated subexpression ([[intro.execution]](intro.execution "6.10.1 Sequential execution")) of a default member initializer is neither evaluated nor checked for whether it is a constant expression at the point where the subexpression appears[.](#15.sentence-4) [16](#16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L813) A member shall not be declared with the extern[*storage-class-specifier*](dcl.stc#nt:storage-class-specifier "9.2.2 Storage class specifiers [dcl.stc]")[.](#16.sentence-1) Within a class definition, a member shall not be declared with the thread_local [*storage-class-specifier*](dcl.stc#nt:storage-class-specifier "9.2.2 Storage class specifiers [dcl.stc]") unless also declared static[.](#16.sentence-2) [17](#17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L817) The [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]") may be omitted in constructor, destructor, and conversion function declarations only; when declaring another kind of member the [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]") shall contain a [*type-specifier*](dcl.type.general#nt:type-specifier "9.2.9.1 General [dcl.type.general]") that is not a [*cv-qualifier*](dcl.decl.general#nt:cv-qualifier "9.3.1 General [dcl.decl.general]")[.](#17.sentence-1) The[*member-declarator-list*](#nt:member-declarator-list "11.4.1 General [class.mem.general]") can be omitted only after a[*class-specifier*](class.pre#nt:class-specifier "11.1 Preamble [class.pre]") or an [*enum-specifier*](dcl.enum#nt:enum-specifier "9.8.1 Enumeration declarations [dcl.enum]") or in a[friend declaration](class.friend "11.8.4 Friends [class.friend]")[.](#17.sentence-2) A[*pure-specifier*](#nt:pure-specifier "11.4.1 General [class.mem.general]") shall be used only in the declaration of a[virtual function](class.virtual "11.7.3 Virtual functions [class.virtual]") that is not a friend declaration[.](#17.sentence-3) [18](#18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L830) The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in a [*member-declaration*](#nt:member-declaration "11.4.1 General [class.mem.general]") appertains to each of the entities declared by the [*member-declarator*](#nt:member-declarator "11.4.1 General [class.mem.general]")*s*; it shall not appear if the optional [*member-declarator-list*](#nt:member-declarator-list "11.4.1 General [class.mem.general]") is omitted[.](#18.sentence-1) [19](#19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L835) A [*virt-specifier-seq*](#nt:virt-specifier-seq "11.4.1 General [class.mem.general]") shall contain at most one of each[*virt-specifier*](#nt:virt-specifier "11.4.1 General [class.mem.general]")[.](#19.sentence-1) A [*virt-specifier-seq*](#nt:virt-specifier-seq "11.4.1 General [class.mem.general]") shall appear only in the first declaration of a virtual member function ([[class.virtual]](class.virtual "11.7.3 Virtual functions"))[.](#19.sentence-2) [20](#20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L842) The type of a non-static data member shall not be an incomplete type ([[basic.types.general]](basic.types.general#term.incomplete.type "6.9.1 General")), an abstract class type ([[class.abstract]](class.abstract "11.7.4 Abstract classes")), or a (possibly multidimensional) array thereof[.](#20.sentence-1) [*Note [5](#note-5)*: In particular, a class C cannot contain a non-static member of class C, but it can contain a pointer or reference to an object of class C[.](#20.sentence-2) — *end note*] [21](#21) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L854) [*Note [6](#note-6)*: See [[expr.prim.id]](expr.prim.id "7.5.5 Names") for restrictions on the use of non-static data members and non-static member functions[.](#21.sentence-1) — *end note*] [22](#22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L860) [*Note [7](#note-7)*: The type of a non-static member function is an ordinary function type, and the type of a non-static data member is an ordinary object type[.](#22.sentence-1) There are no special member function types or data member types[.](#22.sentence-2) — *end note*] [23](#23) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L867) [*Example [3](#example-3)*: A simple example of a class definition isstruct tnode {char tword[20]; int count; tnode* left; tnode* right;}; which contains an array of twenty characters, an integer, and two pointers to objects of the same type[.](#23.sentence-1) Once this definition has been given, the declarationtnode s, *sp; declares s to be a tnode and sp to be a pointer to a tnode[.](#23.sentence-2) With these declarations, sp->count refers to the count member of the object to which sp points;s.left refers to the left subtree pointer of the objects; and s.right->tword[0] refers to the initial character of the tword member of the right subtree of s[.](#23.sentence-3) — *end example*] [24](#24) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L892) [*Note [8](#note-8)*: Non-variant non-static data members of non-zero size ([[intro.object]](intro.object "6.8.2 Object model")) are allocated so that later members have higher addresses within a class object ([[expr.rel]](expr.rel "7.6.9 Relational operators"))[.](#24.sentence-1) Implementation alignment requirements can cause two adjacent members not to be allocated immediately after each other; so can requirements for space for managing virtual functions ([[class.virtual]](class.virtual "11.7.3 Virtual functions")) and virtual base classes ([[class.mi]](class.mi "11.7.2 Multiple base classes"))[.](#24.sentence-2) — *end note*] [25](#25) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L905) If T is the name of a class, then each of the following shall have a name different from T: - [(25.1)](#25.1) every static data member of class T; - [(25.2)](#25.2) every member function of class T; [*Note [9](#note-9)*: This restriction does not apply to constructors, which do not have names ([[class.ctor]](class.ctor "11.4.5 Constructors"))[.](#25.2.sentence-1) — *end note*] - [(25.3)](#25.3) every member of class T that is itself a type; - [(25.4)](#25.4) every member template of class T; - [(25.5)](#25.5) every enumerator of every member of class T that is an unscoped enumeration type; and - [(25.6)](#25.6) every member of every anonymous union that is a member of classT[.](#25.sentence-1) [26](#26) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L928) In addition, if class T has a user-declared[constructor](class.ctor "11.4.5 Constructors [class.ctor]"), every non-static data member of classT shall have a name different from T[.](#26.sentence-1) [27](#27) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L933) The [*common initial sequence*](#def:common_initial_sequence "11.4.1 General [class.mem.general]") of two standard-layout struct ([[class.prop]](class.prop "11.2 Properties of classes")) types is the longest sequence of non-static data members and bit-fields in declaration order, starting with the first such entity in each of the structs, such that - [(27.1)](#27.1) corresponding entities have layout-compatible types ([[basic.types]](basic.types "6.9 Types")), - [(27.2)](#27.2) corresponding entities have the same alignment requirements ([[basic.align]](basic.align "6.8.3 Alignment")), - [(27.3)](#27.3) if a [*has-attribute-expression*](cpp.cond#nt:has-attribute-expression "15.2 Conditional inclusion [cpp.cond]") ([[cpp.cond]](cpp.cond "15.2 Conditional inclusion")) is not 0 for the no_unique_address attribute, then neither entity is declared with the no_unique_address attribute ([[dcl.attr.nouniqueaddr]](dcl.attr.nouniqueaddr "9.13.11 No unique address attribute")), and - [(27.4)](#27.4) either both entities are bit-fields with the same width or neither is a bit-field[.](#27.sentence-1) [*Example [4](#example-4)*: struct A { int a; char b; };struct B { const int b1; volatile char b2; };struct C { int c; unsigned : 0; char b; };struct D { int d; char b : 4; };struct E { unsigned int e; char b; }; The common initial sequence of A and B comprises all members of either class[.](#27.sentence-2) The common initial sequence of A and C and of A and D comprises the first member in each case[.](#27.sentence-3) The common initial sequence of A and E is empty[.](#27.sentence-4) — *end example*] [28](#28) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L967) Two standard-layout struct ([[class.prop]](class.prop "11.2 Properties of classes")) types are[*layout-compatible classes*](#def:layout-compatible,class "11.4.1 General [class.mem.general]") if their common initial sequence comprises all members and bit-fields of both classes ([[basic.types]](basic.types "6.9 Types"))[.](#28.sentence-1) [29](#29) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L973) Two standard-layout unions are layout-compatible if they have the same number of non-static data members and corresponding non-static data members (in any order) have layout-compatible types ([[basic.types.general]](basic.types.general#term.layout.compatible.type "6.9.1 General"))[.](#29.sentence-1) [30](#30) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L979) In a standard-layout union with an [active member](class.union#def:active,union_member "11.5 Unions [class.union]") of struct type T1, it is permitted to read a non-static data member m of another union member of struct type T2 provided m is part of the common initial sequence of T1 and T2; the behavior is as if the corresponding member of T1 were nominated[.](#30.sentence-1) [*Example [5](#example-5)*: struct T1 { int a, b; };struct T2 { int c; double d; };union U { T1 t1; T2 t2; };int f() { U u = { { 1, 2 } }; // active member is t1return u.t2.c; // OK, as if u.t1.a were nominated} — *end example*] [*Note [10](#note-10)*: Reading a volatile object through a glvalue of non-volatile type has undefined behavior ([[dcl.type.cv]](dcl.type.cv "9.2.9.2 The cv-qualifiers"))[.](#30.sentence-2) — *end note*] [31](#31) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1001) If a standard-layout class object has any non-static data members, its address is the same as the address of its first non-static data member if that member is not a bit-field[.](#31.sentence-1) Its address is also the same as the address of each of its base class subobjects[.](#31.sentence-2) [*Note [11](#note-11)*: There can therefore be unnamed padding within a standard-layout struct object inserted by an implementation, but not at its beginning, as necessary to achieve appropriate alignment[.](#31.sentence-3) — *end note*] [*Note [12](#note-12)*: The object and its first subobject are pointer-interconvertible ([[basic.compound]](basic.compound "6.9.4 Compound types"), [[expr.static.cast]](expr.static.cast "7.6.1.9 Static cast"))[.](#31.sentence-4) — *end note*] [32](#32) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1016) A [*data member description*](#def:description,data_member "11.4.1 General [class.mem.general]") is a quintuple (T, N, A, W, NUA) describing the potential declaration of a non-static data member where - [(32.1)](#32.1) T is a type, - [(32.2)](#32.2) N is an [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") or ⊥, - [(32.3)](#32.3) A is an alignment or ⊥, - [(32.4)](#32.4) W is a bit-field width or ⊥, and - [(32.5)](#32.5) NUA is a boolean value[.](#32.sentence-1) Two data member descriptions are equal if each of their respective components are the same entities, are the same identifiers, have equal values, or are both ⊥[.](#32.sentence-2) [*Note [13](#note-13)*: The components of a data member description describe a data member such that - [(32.6)](#32.6) its type is specified using the type given by T, - [(32.7)](#32.7) it is declared with the name given by N if N is not ⊥ and is otherwise unnamed, - [(32.8)](#32.8) it is declared with the [*alignment-specifier*](dcl.attr.grammar#nt:alignment-specifier "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") ([[dcl.align]](dcl.align "9.13.2 Alignment specifier")) given by alignas(A) if A is not ⊥ and is otherwise declared without an [*alignment-specifier*](dcl.attr.grammar#nt:alignment-specifier "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]"), - [(32.9)](#32.9) it is a bit-field ([[class.bit]](class.bit "11.4.10 Bit-fields")) with the width given by W if W is not ⊥ and is otherwise not a bit-field, and - [(32.10)](#32.10) it is declared with the attribute [[no_unique_address]] ([[dcl.attr.nouniqueaddr]](dcl.attr.nouniqueaddr "9.13.11 No unique address attribute")) if NUA is true and is otherwise declared without that attribute[.](#32.sentence-3) Data member descriptions are represented by reflections ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")) returned by std​::​meta​::​data_member_spec ([[meta.reflection.define.aggregate]](meta.reflection.define.aggregate "21.4.16 Reflection class definition generation")) and can be reified as data members of a class using std​::​meta​::​define_aggregate[.](#32.sentence-4) — *end note*]