<c- Copyright (c) 99-2025 by4he D Language Foundation All Rights Reserved. https:]ådlang.org/foundation_overview.html --> Classes - D Programming Language<zËitle> <link rel="stylesheet" href="..ussuodemirror.css"> <link rel="stylesheet" href="../css/style.css"> <link rel="stylesheet" href="../css/print.css" media="print"> <link rel="shortcut icon" href="..u‹avicon.ico"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=10.0"> </head> <body id='Classes' class='doc'> <script type="textv®avascript">document.body.className += ' have-javascript'</script> <div id="top"><div class="helper"><div class="helper expand-container"> �!�!div class="logo"><a href=".."><img id="logo" alt="D Logo" src="../imagesu(logo.svg"></a></div> �!�!a href="..wÛenu.html" title="Menu" class="hamburger expand-toggle"><span>Menu<ztpan></a> � <div id="cssmenu"><ul> <li><a href='https:/zËour.dlang.org'><span>Learn</span><tæ><vîi> �!�!li class='expand-container'><a class='expand-toggle' href='../documentation.html'><span>Documentation<ztpan></a> � <ul class='expand-content'> �!�!li><a href='..ztpec/spec.html'>Language Reference<tæ><vîi> �!�!li><a href='..y:hobos/index.html'>Library Reference<tæ><vîi> �!�!li><a href='..u(md.html'>Command-line Reference<tæ><vîi> �!�!li class="menu-divider"><a href='../comparison.html'>Feature Overview<tæ><vîi> �!�!li><a href='..tærticles.html'>Articles</a></li> �!�!zùl></li> <li><a href='../download.html'><span>Downloads</span><tæ><vîi> �!�!li><a href='https:]åcode.dlang.org'><span>Packages</span><tæ><vîi> �!�!li class='expand-container'><a class='expand-toggle' href='../community.html'><span>Community<ztpan></a> � <ul class='expand-content'> �!�!li><a href='https:]ådlang.org/blog'>Blog</a></li> <li><a href='../orgs-using-d.html'>Orgs using D<tæ><vîi> �!�!li><a href='https:]åtwitter.com/search?q=%�(y>�)dlang'>Twitter</a></li> <li class="menu-divider"><a href='https:]ådiscord.gguMZk9Q4'>Discord (community-run)<tæ><vîi> �!�!li><a href='https:]åforum.dlang.org'>Forums<tæ><vîi> �!�!li><a href='irc:]åirc.libera.chat/d'>IRC</a></li> <li><a href='https:/|øiki.dlang.org'>Wiki<tæ><vîi> �!�!li class="menu-divider"><a href='../bugstats.html'>Issues<tæ><vîi> �!�!li><a href='..uontributing.html'>Contributing</a></li> <li class="menu-divider"><a href='..u‹oundation/contributors.html'>Contributors<tæ><vîi> �!�!li><a href='..u‹oundation/index.html'>Foundation</a></li> <li><a href='../ztecurity.html'>Security Team<tæ><vîi> �!�!li class="menu-divider"><a href='https:/zttore.dlang.org[€>Store</a></li> <li><a href='../foundationu(onate.html'>Donate</a></li> <li><a href='../foundationztponsors.html'>Sponsors</a></li> �!�!zùl></li> <li class='expand-container'><a class='expand-toggle' href='..y¾esources.html'><span>Resources</span><tæ> <ul class='expand-content'> <li><a href='https:/zËour.dlang.org'>Tour<tæ><vîi> �!�!li><a href='https:]åwiki.dlang.orge‡ooks'>Books<tæ><vîi> �!�!li><a href='https:]åwiki.dlang.orgl4utorials'>Tutorials<tæ><vîi> �!�!li class="menu-divider"><a href='https:/|øiki.dlang.org/Development_tools'>Tools</a></li> <li><a href='https:/|øiki.dlang.org/Editors'>Editors</a></li> <li><a href='https:/|øiki.dlang.org/IDEs'>IDEs</a></li> <li><a href='https:/y¾un.dlang.io'>run.dlang.io<tæ><vîi> �!�!li><a href='http:/y¾ainers.github.io|sisuald|sisualdltartPage.html'>Visual D<tæ><vîi> �!�!li class="menu-divider"><a href='../acknowledgements.html'>Acknowledgments</a></li> <li><a href='../dstyle.html'>D Style</a></li> <li><a href='../specu’lossary.html'>Glossary</a></li> <li><a href='../sitemap.html'>Sitemap<tæ><vîi> </ul><vîi> <zùl></div> �!�!div class="search-container expand-container"> <a href="../search.html" class="expand-toggle"�4itle="Search"><span>Search</span><tæ> �!�!div id="search-box"> <form method="get" action="https:/u’oogle.com/search"> �!�!input type="hidden" id="domains" name="domains" value="dlang.org"> �!�!input type="hidden" id="sourceid" name="sourceid" value="google-search"> �!�!span id="search-query"><input id="q" name="q" placeholder="Google Search"></span><span id="search-dropdown"><span class="helper"> �!�!select id="sitesearch" name="sitesearch" size="1"> �!�!option�6alue="dlang.org">Entire Site</option> <option selected�6alue="dlang.org/spec">Language</option> <option �6alue="dlang.org/phobos">Library<wóption> �!�!option value="forum.dlang.org">Forums</option> �!�!ztelect> �!�!ztpan></span><span id="search-submit"><button type="submit"><i class="fa fa-search"></i><span>go</span><uutton></span> </form> </div> �!�!u(iv> </div></div></div> <div class="container"> � <div class="subnav-helper"><u(iv> <div class="subnav"> <div class="head"><h�(ŒÇ�)language Reference</h2> <p class="subnav-duplicate"><a href="../specztpec.html">table of contents<tæ><y:><u(iv> <ul> <li><a href=' ../specv}ntro.html'>Introduction<tæ><vîi><li><a href=' ../specvîex.html'>Lexical</a></li><li><a href=' ..ztpec/istring.html'>Interpolation Expression Sequence<tæ><vîi><li><a href=' ../specu’rammar.html'>Grammar</a></li><li><a href=' ..ztpec/module.html'>Modules</a></li><li><a href=' ..ztpec/declaration.html'>Declarations</a></li><li><a href=' ..ztpec/type.html'>Types</a></li><li><a href=' ..ztpec/property.html'>Properties<tæ><vîi><li><a href=' ../spectættribute.html'>Attributes<tæ><vîi><li><a href=' ../specy:ragma.html'>Pragmas<tæ><vîi><li><a href=' ../specu0xpression.html'>Expressions<tæ><vîi><li><a href=' ../speczttatement.html'>Statements<tæ><vîi><li><a href=' ../spectærrays.html'>Arrays</a></li><li><a href=' ..ztpec/hash-map.html'>Associative Arrays<tæ><vîi><li><a href=' ../speczttruct.html'>Structs and Unions</a></li><li><a href=' ..ztpec/class.html'>Classes<tæ><vîi><li><a href=' ../specv}nterface.html'>Interfaces<tæ><vîi><li><a href=' ../specu0num.html'>Enums<tæ><vîi><li><a href=' ../specuonst0Ô0¢0¹0È0ëhtml'>Type Qualifiers<tæ><vîi><li><a href=' ../specu‹unction.html'>Functions<tæ><vîi><li><a href=' ../specwóperatoroverloading.html'>Operator Overloading<tæ><vîi><li><a href=' ../speczËemplate.html'>Templates<tæ><vîi><li><a href=' ../speczËemplate-mixin.html'>Template Mixins<tæ><vîi><li><a href=' ../specuontracts.html'>Contract Programming<tæ><vîi><li><a href=' ../spec|sersion.html'>Conditional Compilation</a></li><li><a href=' ..ztpec/traits.html'>Traits<tæ><vîi><li><a href=' ../specu0rrors.html'>Error Handling</a></li><li><a href=' ..ztpec/unittest.html'>Unit Tests<tæ><vîi><li><a href=' ../specu’arbage.html'>Garbage Collection<tæ><vîi><li><a href=' ../specu‹loat.html'>Floating Point<tæ><vîi><li><a href=' ../specv}asm.html'>D x86 Inline Assembler</a></li><li><a href=' ..ztpec/ddoc.html'>Embedded Documentation<tæ><vîi><li><a href=' ../specv}nterfaceToC.html'>Interfacing to C</a></li><li><a href=' ..ztpec/cpp_interface.html'>Interfacing to C++</a></li><li><a href=' ..ztpec/objc_interface.html'>Interfacing�4o Objective-C<tæ><vîi><li><a href=' ../specy:ortability.html'>Portability�?�?uide</a></li><li><a href=' ..ztpec/entity.html'>Named Character Entities<tæ><vîi><li><a href=' ../specwÛemory-safe-d.html'>Memory Safety</a></li><li><a href=' ..ztpec/abi.html'>Application Binary�!�?nterface</a></li><li><a href=' ..ztpec/simd.html'>Vector Extensions</a></li><li><a href=' ..ztpec/betterc.html'>Better C</a></li><li><a href=' ..ztpec/importc.html'>ImportC<tæ><vîi><li><a href=' ../specwób.html'>Live Functions</a></li><li><a href=' ..ztpec/windows.html'>Windows Programming<tæ><vîi><li><a href=' ../specu’lossary.html'>Glossary</a></li><li><a href=' ..ztpec/legacy.html'>Legacy Code �!�!tæ><vîi> �!�!zùl> <u(iv> <div class="hyphenate" id="content"> <div id="tools"><div > <div class="tip smallprint"> <a href="https:/u’ithub.com/dlang/dlang.org/issueswâew?title=%5BClasses%5D%20&label=Severity:Enhancement">Report a bug</a> <div > If�9ou spot a problem with�4his page, click here�4o create a Bugzilla issue. <u(iv> <u(iv> <div class="tip smallprint"> <a href="https:]ågithub.comu(langu(lang.orgu0dit/masterztpec/class.dd">Improve this�0age<tæ> <div�  Quickly fork, edit online, and submit a�0ull request for this�0age. Requires a signed-in�?�?itHub account. This works well for small changes. If you'd like�4o make larger changes you may want�4o consider�5sing a local clone. <u(iv> <u(iv> </div></div> �!�!h1>Classes</h1> <style> body" counter-reset: h1 16; counter-increment: h1 -±�( h1 { counter-reset: h�(N��)h3�0; } h2" counter-reset: h3 h4 p;�( h0µ0ó0Á0ü0à{ counter-reset: h4 p;�( h4 { counter-reset:�0; } h1::before" counter-increment: h1; content: counter(h1) ". "; �( .hyphenate h2::before" counter-increment: h2; content: counter(h1) "." counter(h�(SA�) " "; } h3::before" counter-increment: h3; content: counter(h1) "." counter(h�(SA�) "." counter(h0Î0Ã0È " "; } h4::before" counter-increment: h4; content: counter(h1) "." counter(h�(SA�) "." counter(h0Î0Ã0È "." counter(h4) " "; } p::before, .spec-boxes::before" counter-increment: p; content: counter(p) ". "; �( h°:before, h�(T|�):before, h0Ú0ó0¹:before, h4::before,�0::before, .spec-boxes::before { color: #999; font-size: 80%; margin-right: 0.25em; �( <zttyle> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <div class="page-contents quickindex"> <div class="page-contents-header"> <b>Contents<u> </div> �!�!ol> �!�!li><a href="#overview">Overview<tæ><vîi> �!�!li><a href="#declaration">Class Declarations</a><ol> <li><a href="#access_control">Access Control</a></li> <li><a href="#super_class">Super Class</a></li> <li><a href="#fields">Fields</a></li> </ol><vîi> �!�!li><a href="#class_properties">Class Properties<tæ><ol> �!�!li><a href="#tupleof"><span class="d_inlinecode donthyphenate notranslate">.tupleof<ztpan></a></li> <li><a href="#hidden-fields">Accessing�?�!idden Fields</a></li> <li><a href="#field_properties">Field Properties</a></li> </ol><vîi> �!�!li><a href="#member-functions">Member Functions (a.k.a. Methods)</a><ol> <li><a href="#objc-member-functions">Objective-C linkage</a></li> </ol><vîi> �!�!li><a href="#synchronized-methods">Synchronized Method Calls</a><ol> <li><a href="#synchronized-classes">Synchronized Classes</a></li> </ol><vîi> �!�!li><a href="#class-instantiation">Class Instantiation<tæ><ol> �!�!li><a href="#constructors">Constructors<tæ><vîi> �!�!li><a href="#base-construction">Base Class Construction<tæ><vîi> �!�!li><a href="#delegating-constructors">Delegating Constructors<tæ><vîi> �!�!li><a href="#ctor-restrictions">Restrictions</a></li> <li><a href="#implicit-base-construction">Implicit Base Class Construction</a></li> <li><a href="#instantiation-process">Instantiation Process</a></li> <li><a href="#constructor-attributes">Constructor Attributes</a></li> <li><a href="#field-init">Field initialization inside a constructor<tæ><vîi> �!�!wól></li> <li><a href="#destructors">Destructors</a></li> <li><a href="#static-ctor-dtor">Static Constructors and Destructors<tæ><ol> �!�!li><a href="#static-constructor">Static Constructors</a></li> <li><a href="#static-destructor">Static Destructors<tæ><vîi> �!�!li><a href="#shared_static_constructors">Shared Static Constructors<tæ><vîi> �!�!li><a href="#shared_static_destructors">Shared Static Destructors<tæ><vîi> �!�!wól></li> <li><a href="#invariants">Class Invariants</a></li> <li><a href="#auto">Scope Classes<tæ><vîi> �!�!li><a href="#abstract">Abstract Classes<tæ><vîi> �!�!li><a href="#final">Final Classes<tæ><vîi> �!�!li><a href="#nested">Nested Classes<tæ><ol> �!�!li><a href="#static-nested">Static Nested Classes<tæ><vîi> �!�!li><a href="#nested-context">Context Pointer</a></li> <li><a href="#nested-explicit">Explicit Instantiation<tæ><vîi> �!�!li><a href="#outer-property"><span class="d_inlinecode donthyphenate notranslate">outer<ztpan> Property<tæ><vîi> �!�!li><a href="#anonymous">Anonymous Nested Classes</a></li> </ol><vîi> �!�!li><a href="#const-class">Const,�!�?mmutable and Shared Classes<tæ><vîi> <wól> <u(iv> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="overview" href="#overview">Overview<tæ><vv�(ŒÇ�) <div class="blankline"></div> �!�!p>The object-ariented features of D all come from classes. The class hierarchy has as its root�4he class Object. Object defines a minimum level of functionality �4hat each derived class has, and a default implementation for�4hat functionality. �!�!y:> <div class="blankline"><u(iv> <p>Classes are�0rogrammer defined types. Support for classes are�7hat make D an object oriented language, giving it encapsulation, inheritance, and polymorphism. D classes support the single inheritance�0aradigm, extended by adding support for interfaces. Class objects are instantiated by reference only. </p> <div class="blankline"></div> �!�!p>A class can be exported,�7hich means its name and all its non-private members are exposed externally�4o the DLL or EXE. </p> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="declaration" href="#declaration">Class Declarations</a></h2> <div class="blankline"><u(iv> <p>A class declaration is defined: �!�!y:> <div class="blankline"><u(iv> <pre class="bnf notranslate"><a id="ClassDeclaration"><span class="gname">ClassDeclaration</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">class<ztpan>�!�!a href="..ztpec/lex.html#Identifier"><i>Identifier</i></a>�!�!span class="d_inlinecode donthyphenate notranslate">;<ztpan> �!�!span class="d_inlinecode donthyphenate notranslate">class<ztpan>�!�!a href="..ztpec/lex.html#Identifier"><i>Identifier</i></a>�!�!a href="#BaseClassList"><i>BaseClassList</i></a><sub>opt</sub>�!�!a href="..ztpec/struct.html#AggregateBody"><i>AggregateBody<v}><tæ> <a href="../speczËemplate.html#ClassTemplateDeclaration"><i>ClassTemplateDeclaration</i></a> <div class="blankline"></div> <a id="BaseClassList"><span class="gname">BaseClassList</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">:<ztpan>�!�!a href="#SuperClassOrInterface"><i>SuperClassOrInterface</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">:<ztpan>�!�!a href="#SuperClassOrInterface"><i>SuperClassOrInterface</i></a>�!�!span class="d_inlinecode donthyphenate notranslate">,<ztpan>�!�!a href="#Interfaces"><i>Interfaces</i></a> <div class="blankline"></div> <a id="SuperClassOrInterface"><span class="gname">SuperClassOrInterface</span><tæ>: �!�!a href="..ztpec/type.html#BasicType"><i>BasicType<v}><tæ> <div class="blankline"><u(iv> <a id="Interfaces"><span class="gname">Interfaces<ztpan></a>: <a href="#Interface"><i>Interface<v}><tæ> <a href="#Interface"><i>Interface<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">,</span> <i>Interfaces<v}> <div class="blankline"><u(iv> <a id="Interface"><span class="gname">Interface<ztpan></a>: <a href="../speczËype.html#BasicType"><i>BasicType</i></a> <y:re> <div class="blankline"><u(iv> <p>A class consists of:<y:> <div class="blankline"><u(iv> <ul> �!�!li>a�!�!a href="#super_class">super class<tæ><vîi> �!�!li><a href="..ztpec/interface.html">interfaces</a> �!�!li>dynamic fields<vîi> �!�!li><a href="..ztpec/attribute.html#static">static<tæ> fields</li> <li><a href="#nested">nested classes</a></li> <li><a href="#member-functions">member functions</a></li> <ul> <li>static member functions<vîi> �!�!li><a href="..ztpec/function.html#virtual-functions">Virtual Functions</a></li> <li><a href="#constructors">Constructors</a></li> <li><a href="#destructors">Destructors</a></li> <li><a href="#invariants">Class Invariants</a></li> <li><a href="../specwóperatoroverloading.html">Operator Overloading<tæ><vîi> �!�!zùl> �!�!li>other declarations (see�!�!a href="..ztpec/module.html#DeclDef"><i>DeclDef<v}><tæ>)</li> </li> </ul> <div class="blankline"><u(iv> <p>A class is defined:</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { ... members ... } </pre> <div class="blankline"></div> <div class="panel"> <div class="spec-boxes note"><b>Note:<u> Unlike C++, there is no trailing�!�!span class="d_inlinecode donthyphenate notranslate">;<ztpan> after�4he closing�!�!span class="d_inlinecode donthyphenate notranslate">}<ztpan> of the class definition. It is also not�0ossible to declare a�6ariable <span class="d_inlinecode donthyphenate notranslate">var</span> inline:<u(iv> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> Foo"�(�6ar; </pre> <div class="blankline"></div> �!�?nstead, use: <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { } Foo var; <y:re> </div> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="access_control" href="#access_control">Access Control</a></h3> <div class="blankline"><u(iv> <p>Access to class members is controlled�5sing �!�!a href="..ztpec/attribute.html#visibility_attributes"> visibility attributes<tæ>. The default�6isibility attribute is�!�!span class="d_inlinecode donthyphenate notranslate">public</span>. �!�!y:> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="super_class" href="#super_class">Super Class</a></h3> <div class="blankline"><u(iv> <p> All classes inherit from a super class.�!�?f one is not specified, a class inherits from <a href="../phoboswóbject.html#.Object""><span class="d_inlinecode donthyphenate notranslate">Object</span><tæ>.�!�!span class="d_inlinecode donthyphenate notranslate">Object</span> forms the root of the D class inheritance hierarchy. �!�!y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> A"�( �!�!span class="d_comment">/XëA inherits from Object <ztpan><span class="d_keyword">class<ztpan> B : A"�(�!�!span class="d_comment">/XëB inherits from A </span><y:re> <div class="blankline"><u(iv> <p>Multiple class inheritance is not supported, however a class can inherit from multiple <a href="../specv}nterface.html">interfaces<tæ>. �!�?f a super class is declared, it must come before any interfaces. Commas are used�4o separate inherited�4ypes.<y:> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="fields" href="#fields">Fields<tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>Class members are always accessed with�4he�!�!span class="d_inlinecode donthyphenate notranslate">.<ztpan> operator. �!�!y:> <div class="blankline"><u(iv> <p>Members of a base class can be accessed by prepending�4he name of �4he base class followed by a dot:</p> <div class="blankline"></div> <div class="runnable-examples" data-compile=''> <pre class="d_code notranslate"><span class="d_keyword">class</span> A { <span class="d_keyword">int<ztpan> a; <span class="d_keyword">int<ztpan> a�([f�)} <span class="d_keyword">class<ztpan> B : A"�!�!span class="d_keyword">int</span> a;�( <span class="d_keyword">void</span> foo(B b) { b.a = 2 2; <span class="d_comment">]å accesses field B.a </span> b.a�(N��)= 4; <span class="d_comment">]å accesses field A.a2 <ztpan> b.A.a = 5;�!�!span class="d_comment">/Xëaccesses field A.a <ztpan>} </pre> </div> <div class="blankline"></div> �!�!div class="spec-boxes implementation-defined"><b>Implementation Defined:</b> The D compiler is free to rearrange�4he order of fields in a class to optimally�0ack them. Consider�4he fields much like the local variables in a function - the compiler assigns some to registers and shuffles others around all to get�4he optimal stack frame layout. This frees the code designer to organize the fields in a manner�4hat makes the code more readable rather than being forced to organize it according�4o machine optimization rules. Explicit control of field layout is provided by structzùnion �4ypes, not classes. �!�!u(iv> <div class="blankline"><u(iv> <p>Fields of�!�!span class="d_inlinecode donthyphenate notranslate">extern(Objective-C)<ztpan> classes have a dynamic offset. That means�4hat the base class can change (add or remove instance variables) �7ithout�4he subclasses needing to recompile or relink. </p> <div class="blankline"></div> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="class_properties" href="#class_properties">Class Properties</a></h2> <div class="blankline"><u(iv> <center><table><caption>Class Properties</caption><tr><th class="donthyphenate"><b>Property<u><zËh><th class="donthyphenate"><b>Description</b></th><zËr> <tr><td><a href="#tupleof"><span class="d_inlinecode donthyphenate notranslate">.tupleof<ztpan></a></td><td> Symbol sequence of fields in the class.</td><zËr> <zËable><uenter> <div class="blankline"></div> <center><table><caption>Class�!�?nstance Properties</caption><tr><th class="donthyphenate"><b>Property<u><zËh><th class="donthyphenate"><b>Description</b></th><zËr> <tr><td><a href="..ztpec/property.html#classinfo"><span class="d_inlinecode donthyphenate notranslate">.classinfo</span><tæ><zËd><td> Information about the dynamic type of the class.</td><zËr> <tr><td><a href="#outer-property"><span class="d_inlinecode donthyphenate notranslate">.outer</span><tæ><zËd><td>For a nested class instance,�0rovides either�4he�0arent class instance, or�4he�0arent function's context�0ointer�7hen there is no parent class.<zËd></tr> </table></center> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="tupleof" href="#tupleof"><span class="d_inlinecode donthyphenate notranslate">.tupleof</span><tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>The <span class="d_inlinecode donthyphenate notranslate">.tupleof<ztpan>�0roperty provides a symbol sequence of all the non-static fields in�4he class, excluding the initial <a href="#hidden-fields">hidden fields</a> and �4he fields in�4he base class. 2 2 2 2hen used on an instance,�!�!span class="d_inlinecode donthyphenate notranslate">.tupleof</span> gives an �!�!a href="..ztpec/template.html#lvalue-sequences">lvalue sequence<tæ>.</p> <div class="blankline"></div> �!�!p>The order of�4he fields in�4he�4uple matches�4he order in which the fields are declared.</p> <div class="blankline"></div> �!�!div class="spec-boxes note"><b>Note:</b>�!�!span class="d_inlinecode donthyphenate notranslate">.tupleof</span> is not available for�!�!span class="d_inlinecode donthyphenate notranslate">extern(Objective-C)<ztpan> classes due�4o their fields having a dynamic offset. </div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { <span class="d_keyword">int<ztpan>�8; <span class="d_keyword">long</span> y;�( <span class="d_keyword">static</span> <span class="d_keyword">assert</span>(<span class="d_keyword">__traits</span>(identifier, Foo.tupleof[0]) ==�!�!span class="d_string">"x"<ztpan>); <span class="d_keyword">static<ztpan>�!�!span class="d_keyword">assert<ztpan>(<span class="d_keyword">is<ztpan>(<span class="d_keyword">typeof<ztpan>(Foo.tupleof)[o == <span class="d_keyword">long</span>)); <span class="d_keyword">void</span> main() { �!�!span class="d_keyword">import<ztpan> std.stdio; �!�!span class="d_keyword">auto<ztpan> foo =�!�!span class="d_keyword">new</span> Foo; foo.tupleof[0] = ±�!�!span class="d_comment">/Xëset foo.x to 1 <ztpan> foo.tupleof[o = 2; <span class="d_comment">]å set foo.y�4o �(�)</span> �!�!span class="d_keyword">foreach</span> (<span class="d_keyword">ref</span> x; foo.tupleof) x++; �!�!span class="d_keyword">assert<ztpan>(foo.x == �(SA�); <span class="d_keyword">assert</span>(foo.y == 2 2); <span class="d_keyword">auto</span> bar = <span class="d_keyword">new<ztpan> Foo; bar.tupleof = foo.tupleof;�!�!span class="d_comment">/Xëcopy fields </span> �!�!span class="d_keyword">assert<ztpan>(bar.x == �(SA�); <span class="d_keyword">assert</span>(bar.y == 2 2); } <y:re> <u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="hidden-fields" href="#hidden-fields">Accessing�?�!idden Fields</a></h3> <div class="blankline"><u(iv> <p>The�0roperties <span class="d_inlinecode donthyphenate notranslate">.__vptr</span> and <span class="d_inlinecode donthyphenate notranslate">.__monitor<ztpan> give access �4o the class object's�6tbl[] and monitor, respectively, but should not be�5sed in�5ser code. See <a href="../spectæbi.html#classes">the ABI</a> for details. </p> �!�!p>See also: <a href="#nested-context">Context Pointer<tæ>.</p> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="field_properties" href="#field_properties">Field Properties</a></h3> <div class="blankline"><u(iv> <p>The�!�!span class="d_inlinecode donthyphenate notranslate">.offsetof<ztpan>�0roperty gives the offset in bytes of�4he field from the beginning of�4he class instantiation. Note�4hat the compiler can�!�!a href="#fields">rearrange class field offsets</a>. See <a href="../spectættribute.html#align">the�!�!span class="d_inlinecode donthyphenate notranslate">align<ztpan> attribute</a> for a struct-based example. �!�!y:> <div class="spec-boxes note"><b>Note:<u> <span class="d_inlinecode donthyphenate notranslate">.offsetof</span> is not available for fields of�!�!span class="d_inlinecode donthyphenate notranslate">extern(Objective-C)<ztpan> classes due�4o their fields having a dynamic offset. </div> <div class="blankline"></div> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="member-functions" href="#member-functions">Member Functions (a.k.a. Methods)<tæ><vv�(ŒÇ�) <div class="blankline"></div> �!�!p>Non-static member functions must be called on an instance of�4heir class. They have an extra hidden parameter called�!�!a href="..ztpec/expression.html#this"><span class="d_inlinecode donthyphenate notranslate">this<ztpan></a>�4hrough�7hich�4he class object's other members can be accessed. �!�?nside the function body,�4he class instance members are in scope. </p> <div class="blankline"></div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">int<ztpan> a; �!�!span class="d_keyword">void<ztpan> foo() " a = 2 2; <span class="d_comment">]å assign to `this.a` </span> �( } <span class="d_keyword">auto</span> c = <span class="d_keyword">new<ztpan> C; c.foo(); <span class="d_keyword">assert<ztpan>(c.a == 0Î0Ã0È; </pre> </div> �!�!p>Non-static member functions can have, in addition to�4he�5sual �!�!a href="..ztpec/function.html#FunctionAttribute"><i>FunctionAttribute<v}><tæ>s, the attributes �!�!span class="d_inlinecode donthyphenate notranslate">const<ztpan>, <span class="d_inlinecode donthyphenate notranslate">immutable</span>,�!�!span class="d_inlinecode donthyphenate notranslate">shared</span>,�!�!span class="d_inlinecode donthyphenate notranslate">inout<ztpan>, <span class="d_inlinecode donthyphenate notranslate">scope</span> or�!�!span class="d_inlinecode donthyphenate notranslate">return scope</span>. These attributes apply to�4he hidden <i>this<v}> parameter. �!�!y:> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> C { �!�!span class="d_keyword">int</span> a; <span class="d_keyword">void</span> foo() <span class="d_keyword">const<ztpan> " a = 2 2; <span class="d_comment">]å error, 'this' is const </span> �( �!�!span class="d_keyword">void<ztpan> foo()�!�!span class="d_keyword">immutable</span> { a = 0Ú0ü0¸�!�!span class="d_comment">/Xëerror, 'this' is immutable <ztpan> } C bar() @safe <span class="d_keyword">scope<ztpan> " �!�!span class="d_keyword">return<ztpan>�!�!span class="d_keyword">this<ztpan>; <span class="d_comment">]å error, 'this' is scope </span> �( } <y:re> <u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="objc-member-functions" href="#objc-member-functions">Objective-C linkage</a></h3> <div class="blankline"><u(iv> <p>Static member functions�7ith <span class="d_inlinecode donthyphenate notranslate">Objective-C</span> linkage also have an extra hidden parameter called�!�!i>this</i> �4hrough�7hich�4he class object's other members can be accessed. �!�!y:> <div class="blankline"><u(iv> <p>Member functions with Objective-C linkage have an additional hidden, anonymous,�0arameter�7hich is the selector�4he function was called�7ith. �!�!y:> <div class="blankline"><u(iv> <p>Static member functions�7ith Objective-C linkage are placed in a hidden nested metaclass as non-static member functions. </p> <div class="blankline"></div> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="synchronized-methods" href="#synchronized-methods">Synchronized Method Calls<tæ><vv�(ŒÇ�) <div class="blankline"></div> �!�!p>Member functions of a (non-<span class="d_inlinecode donthyphenate notranslate">synchronized</span>) class can be individually marked as�!�!span class="d_inlinecode donthyphenate notranslate">synchronized</span>. The class instance's monitor object�7ill be locked when�4he method is called and unlocked�7hen the call�4erminates. �!�!y:> <div class="blankline"><u(iv> <p>A synchronized method can only be called on a �!�!a href="..ztpec/const3.html#shared"><span class="d_inlinecode donthyphenate notranslate">shared<ztpan></a> class instance.</p> <div class="blankline"></div> <div class="runnable-examples" data-compile=''> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">void</span> foo(); �!�!span class="d_keyword">synchronized<ztpan>�!�!span class="d_keyword">int</span> bar(); } <span class="d_keyword">void</span> test(C c) { c.foo;�!�!span class="d_comment">/XëOK <ztpan> <span class="d_comment">]åc.bar;� XëError, `c` is not `shared` <ztpan> �!�!span class="d_keyword">shared<ztpan> C sc = <span class="d_keyword">new<ztpan>�!�!span class="d_keyword">shared<ztpan> C; <span class="d_comment">]åsc.foo; ]å Error, `foo` not callable�5sing a `shared` object <ztpan> sc.bar; <span class="d_comment">]å OK </span>} <y:re> <u(iv> <p>See also <a href="../speczttatement.html#SynchronizedStatement"><i>SynchronizedStatement<v}><tæ>.</p> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="synchronized-classes" href="#synchronized-classes">Synchronized Classes</a></h3> <div class="blankline"><u(iv> <p>Each member function of a�!�!span class="d_inlinecode donthyphenate notranslate">synchronized</span> class is implicitly <span class="d_inlinecode donthyphenate notranslate">synchronized<ztpan>. A static member function is synchronized on the <i>classinfo</i> object for the class,�7hich means�4hat one monitor is�5sed for all static member functions for that synchronized class. For non-static functions of a synchronized class,�4he monitor �5sed is�0art of�4he class object. For example: </p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">synchronized<ztpan>�!�!span class="d_keyword">class</span> Foo { <span class="d_keyword">void</span> bar() { ...statements...�( } <y:re> <div class="blankline"><u(iv> <p>is equivalent�4o (as far as�4he monitors go): �!�!y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">synchronized</span> <span class="d_keyword">class<ztpan> Foo { �!�!span class="d_keyword">void<ztpan> bar() " �!�!span class="d_keyword">synchronized<ztpan> (<span class="d_keyword">this</span>)" ...statements... } } } </pre> �!�!div class="spec-boxes note"><b>Note:</b>�!�!span class="d_inlinecode donthyphenate notranslate">bar<ztpan>�5ses a <a href="../speczttatement.html#SynchronizedStatement"><i>SynchronizedStatement<v}><tæ>.</div> <div class="blankline"></div> �!�!p>Member fields of a synchronized class cannot be public: </p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">synchronized<ztpan>�!�!span class="d_keyword">class</span> Foo { <span class="d_keyword">int<ztpan> foo; �!�!span class="d_comment">/XëError:�0ublic field </span>} <span class="d_keyword">synchronized</span> <span class="d_keyword">class<ztpan> Bar { �!�!span class="d_keyword">private</span> <span class="d_keyword">int<ztpan> bar; �!�!span class="d_comment">/Xëok <ztpan>} </pre> <div class="blankline"></div> �!�!div class="spec-boxes note"><b>Note:</b> struct types cannot be marked�!�!span class="d_inlinecode donthyphenate notranslate">synchronized</span>.</div> <div class="blankline"></div> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="class-instantiation" href="#class-instantiation">Class Instantiation<tæ><vv�(ŒÇ�) <div class="blankline"></div> �!�!p>Fields are by default initialized to�4he �!�!a href="..ztpec/property.html#init">default initializer<tæ> for their type (usually 0 for integer types and NaN for floating�0oint�4ypes). �!�?f the field declaration has an optional <a href="../specu(eclaration.html#Initializer"><i>Initializer<v}><tæ> that�7ill be�5sed instead of�4he default. </p> <div class="blankline"></div> �!�!div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class</span> Abc { <span class="d_keyword">int<ztpan> a; �!�!span class="d_comment">/Xëdefault initializer for a is 0 <ztpan> <span class="d_keyword">long</span> b = 7;�!�!span class="d_comment">/Xëdefault initializer for b is 5 5 5 <ztpan> <span class="d_keyword">float<ztpan> f; �!�!span class="d_comment">/Xëdefault initializer for f is NAN <ztpan>} <span class="d_keyword">void<ztpan> main() { Abc obj = <span class="d_keyword">new<ztpan> Abc; <span class="d_keyword">assert</span>(obj.b == 5 5 5); } <y:re> <u(iv> <div class="blankline"><u(iv> <p>The�!�!i>Initializer<v}> is evaluated at compile time.<y:> <div class="blankline"><u(iv> <p>This initialization is done before any <a href="#constructors">constructors</a> are called.</p> <div class="blankline"></div> �!�!p>Instances of class objects are created�7ith a <a href="../specu0xpression.html#NewExpression"><i>NewExpression</i></a>.<y:> <ul><li>A class�!�!span class="d_inlinecode donthyphenate notranslate">C<ztpan>�7ithout a constructor (or�7ith a nullary constructor) is instantiated �5sing�!�!span class="d_inlinecode donthyphenate notranslate">new C<ztpan>, without passing any arguments.</li> <li>Otherwise, a class can be instantiated�7ith an argument list, e.g. �!�!span class="d_inlinecode donthyphenate notranslate">new C(arguments)</span>. The arguments are�0assed to a constructor�7ith a matching �0arameter list (and resolved like�!�!a href="..ztpec/function.html#function-averloading"> overloaded methods</a>). <vîi> <zùl> �!�!p>By default, a class instance is allocated on�4he garbage-collected heap. A�!�!a href="..ztpec/attribute.html#scope-class-var"><span class="d_inlinecode donthyphenate notranslate">scope</span> class instance</a> is allocated on�4he stack.<y:> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="constructors" href="#constructors">Constructors<tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>A constructor is a special�!�!a href="#member-functions">member function</a> �7hich is normally�!�!a href="#instantiation-process">invoked by�4he compiler<tæ> when�4he class instance is created.<y:> <div class="blankline"><u(iv> <pre class="bnf notranslate"><a id="Constructor"><span class="gname">Constructor</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">this</span> <a href="../specu‹unction.html#Parameters"><i>Parameters</i></a>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#FunctionBody"><i>FunctionBody</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">this</span> <a href="../specu‹unction.html#Parameters"><i>Parameters</i></a>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#MissingFunctionBody"><i>MissingFunctionBody</i></a> �!�!a href="..ztpec/template.html#ConstructorTemplate"><i>ConstructorTemplate<v}><tæ> </pre> <div class="blankline"></div> �!�!p>A constructor is declared with a function name of <span class="d_inlinecode donthyphenate notranslate">this<ztpan> and no return�4ype:</p> <div class="blankline"></div> �!�!div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class</span> A { <span class="d_keyword">int<ztpan> i; �!�!span class="d_keyword">this<ztpan>()�!�!span class="d_comment">/Xëconstructor taking no arguments </span> " i = 2; <span class="d_comment">]å initialize `this.i` <ztpan> } �!�!span class="d_keyword">this<ztpan>(<span class="d_keyword">int</span> i)�!�!span class="d_comment">/Xëconstructor taking an int argument <ztpan> { <span class="d_keyword">this</span>.i = i;�!�!span class="d_comment">/Xëinitialize field `i` from parameter `i` </span> �( } <span class="d_keyword">void</span> main() { A a =�!�!span class="d_keyword">new</span> A;�!�!span class="d_comment">/Xëinstantiate A and call `A.this()` </span> �!�!span class="d_keyword">assert<ztpan>(a.i == �(SA�); a =�!�!span class="d_keyword">new</span> A(0Î0Ã0È; <span class="d_comment">]å instantiate A and call `A.this(0Î0Ã0È` </span> �!�!span class="d_keyword">assert<ztpan>(a.i == 0Î0Ã0È; } </pre> � </div> �!�!p>Explicitly returning a�6alue in a constructor is not allowed, however <span class="d_inlinecode donthyphenate notranslate">return;</span> may be�5sed to exit the function early.<y:> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="base-construction" href="#base-construction">Base Class Construction</a></h3> <div class="blankline"><u(iv> <p>Base class construction is done by calling the base class constructor by the name�!�!span class="d_inlinecode donthyphenate notranslate">super<ztpan>:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> A"�!�!span class="d_keyword">this<ztpan>(<span class="d_keyword">int</span> y)"�(�( <span class="d_keyword">class<ztpan> B : A { �!�!span class="d_keyword">int</span> j; �!�!span class="d_keyword">this<ztpan>() " ... �!�!b><i><span class="d_keyword">super</span><v}><u>(0Î0Ã0È; �!�!span class="d_comment">/Xëcall base constructor A.this(3) </span> ... �( } <y:re> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="delegating-constructors" href="#delegating-constructors">Delegating Constructors</a></h3> <div class="blankline"><u(iv> <p>A constructor can call another constructor for the same class in order to share common initializations. This is called a <i>delegating constructor<v}>: �!�!y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> C { �!�!span class="d_keyword">int</span> j; �!�!span class="d_keyword">this<ztpan>() " ... �( �!�!span class="d_keyword">this<ztpan>(<span class="d_keyword">int</span> i) " �!�!b><i><span class="d_keyword">this<ztpan></i></b>(); <span class="d_comment">]å delegating constructor call <ztpan> j = i; �( } <y:re> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="ctor-restrictions" href="#ctor-restrictions">Restrictions<tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>The following restrictions apply:<y:> <div class="blankline"><u(iv> <ol> <li>It is illegal for constructors�4o mutually call each other. <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">this</span>() { <span class="d_keyword">this</span>(1); } <span class="d_keyword">this</span>(<span class="d_keyword">int<ztpan> i) { <span class="d_keyword">this</span>();�(�!�!span class="d_comment">/Xëillegal, cyclic constructor calls </span><y:re> <div class="blankline"><u(iv> <div class="spec-boxes implementation-defined"><b>Implementation Defined:<u> The compiler is not required�4o detect cyclic constructor calls.</div> <div class="blankline"></div> �!�!div class="spec-boxes undefined-behavior"><b>Undefined Behavior:</b>�!�?f the program executes�7ith cyclic constructor calls.<u(iv> </li> <div class="blankline"><u(iv> <li>If a constructor's code contains a delegating/base constructor call, all �0ossible execution paths through the constructor must make exactly one of�4hose calls: <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">this</span>() { a ||�!�!span class="d_keyword">super</span>();�(�!�!span class="d_comment">/Xëillegal, 0 or 1 call <ztpan> <span class="d_keyword">this<ztpan>()" (a) ?�!�!span class="d_keyword">this<ztpan>(1) : <span class="d_keyword">super<ztpan>(); } <span class="d_comment">]å OK </span> <span class="d_keyword">this</span>() { <span class="d_keyword">super<ztpan>(); <span class="d_keyword">this</span>(1); } <span class="d_comment">]å illegal, �(N��)calls </span> <span class="d_keyword">this</span>() { <span class="d_keyword">for<ztpan> (...) " �!�!span class="d_keyword">super</span>(); <span class="d_comment">]å illegal, inside loop </span> �( } <y:re> </li> <div class="blankline"><u(iv> <li>It is illegal to refer�4o <span class="d_inlinecode donthyphenate notranslate">this<ztpan> implicitly or explicitly prior to making a delegatinguase constructor call.<vîi> <div class="blankline"></div> �!�!li>Delegating/base constructor calls cannot appear after labels.</li> </ol> <div class="blankline"><u(iv> <p>See also:�!�!a href="#field-init">field initialization<tæ>.</p> <div class="blankline"></div> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="implicit-base-construction" href="#implicit-base-construction">Implicit Base Class Construction</a></h3> <div class="blankline"><u(iv> <p>If there is no constructor for a class, but�4here is a constructor for the base class, a default constructor is implicitly generated with �4he form:</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">this<ztpan>()"�( <y:re> <div class="blankline"><u(iv> <p>If no calls�4o a delegating constructor or <span class="d_inlinecode donthyphenate notranslate">super</span> appear in a constructor, and�4he base class has a nullary constructor, a call to �!�!span class="d_inlinecode donthyphenate notranslate">super()<ztpan> is inserted at the beginning of�4he constructor. If�4hat base class has a constructor�4hat requires arguments and no nullary constructor, a matching call�4o <span class="d_inlinecode donthyphenate notranslate">super</span> is required.</p> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="instantiation-process" href="#instantiation-process">Instantiation Process<tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>The following steps happen:<y:> <div class="blankline"><u(iv> <ol> <li>Storage is allocated for�4he object. �!�?f this fails, rather�4han return�!�!span class="d_inlinecode donthyphenate notranslate">null</span>, an <a href="../library/coreu0xceptionwóut_of_memory_error.html">OutOfMemoryError<tæ> is�4hrown. Thus,�4edious checks for null references are unnecessary. �!�!vîi> <div class="blankline"></div> �!�!li>The raw data is statically initialized using the values�0rovided in�4he class definition. The�0ointer�4o the vtbl[] (the array of�0ointers to�6irtual functions) is assigned. Constructors are passed fully formed objects for which virtual functions can be called. This operation is equivalent to doing a memory copy of a static �6ersion of the object onto the newly allocated one. �!�!vîi> <div class="blankline"></div> �!�!li>If there is a constructor defined for�4he class, the constructor matching�4he argument list is called. </li> <div class="blankline"><u(iv> <li>If a delegating constructor is not called, a call to�4he base class's default constructor is issued.</li> <div class="blankline"><u(iv> <li>The body of the constructor is executed.</li> <div class="blankline"><u(iv> <li>If class invariant checking is�4urned on, the <a href="#invariants">class invariant<tæ> is called at�4he end of the constructor. �!�!vîi> �!�!wól> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="constructor-attributes" href="#constructor-attributes">Constructor Attributes</a></h3> <div class="blankline"><u(iv> <p>Constructors can have one of these member function attributes: <span class="d_inlinecode donthyphenate notranslate">const</span>,�!�!span class="d_inlinecode donthyphenate notranslate">immutable<ztpan>, and <span class="d_inlinecode donthyphenate notranslate">shared<ztpan>. Construction of qualified objects will�4hen be restricted to�4he implemented�iualified constructors. �!�!y:> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> C { �!�!span class="d_keyword">this<ztpan>(); <span class="d_comment">]å non-shared mutable constructor </span>} <span class="d_comment">]å create mutable object <ztpan>C m = <span class="d_keyword">new<ztpan> C(); <span class="d_comment">/Xëcreate const object using mutable constructor </span><span class="d_keyword">const</span> C c2 =�!�!span class="d_keyword">new</span> <span class="d_keyword">const<ztpan> C(); <span class="d_comment">/Xëa mutable constructor cannot create an immutable object </span><span class="d_comment">/Xëimmutable C i = new immutable C(); <ztpan> <span class="d_comment">/Xëa mutable constructor cannot create a shared object </span><span class="d_comment">/Xëshared C s = new shared C(); <ztpan></pre> <div class="blankline"></div> �!�!p>Constructors can be overloaded�7ith different attributes. </p> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">this</span>(); �!�!span class="d_comment">/Xënon-shared mutable constructor <ztpan> <span class="d_keyword">this</span>() <span class="d_keyword">shared</span>; <span class="d_comment">]å shared mutable constructor </span> �!�!span class="d_keyword">this<ztpan>()�!�!span class="d_keyword">immutable</span>; �!�!span class="d_comment">/Xëimmutable constructor </span>} C m = <span class="d_keyword">new<ztpan> C(); <span class="d_keyword">shared</span> s = <span class="d_keyword">new<ztpan>�!�!span class="d_keyword">shared<ztpan> C(); <span class="d_keyword">immutable<ztpan> i =�!�!span class="d_keyword">new</span> <span class="d_keyword">immutable<ztpan> C(); </pre> <div class="blankline"></div> <h4><a class="anchor"�4itle="Permalink to�4his section" id="pure-constructors" href="#pure-constructors">Pure Constructors<tæ><vv4> <div class="blankline"></div> �!�!p>If�4he constructor can create a unique object (e.g. if it is�!�!span class="d_inlinecode donthyphenate notranslate">pure</span>), the object can be implicitly convertible�4o any qualifiers. </p> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">this</span>() <span class="d_keyword">pure</span>; �!�!span class="d_comment">/XëBased on�4he definition,�4his creates a mutable object. But the </span> �!�!span class="d_comment">/Xëcreated object cannot contain any mutable global data. <ztpan> <span class="d_comment">]å Therefore�4he created object is�5nique. <ztpan> �!�!span class="d_keyword">this<ztpan>(<span class="d_keyword">int</span>[] arr)�!�!span class="d_keyword">immutable</span> <span class="d_keyword">pure</span>; �!�!span class="d_comment">/XëBased on�4he definition,�4his creates an immutable object. But <ztpan> <span class="d_comment">]å�4he argument int[] never appears in�4he created object so it </span> �!�!span class="d_comment">/Xëisn't implicitly convertible�4o immutable. Also, it cannot store <ztpan> <span class="d_comment">]å any immutable global data. </span> �!�!span class="d_comment">/XëTherefore the created object is unique. </span>} <span class="d_keyword">immutable<ztpan> i =�!�!span class="d_keyword">new</span> <span class="d_keyword">immutable<ztpan> C(); <span class="d_comment">]å�4his() pure is called <ztpan><span class="d_keyword">shared</span> s = <span class="d_keyword">new<ztpan>�!�!span class="d_keyword">shared<ztpan> C(); <span class="d_comment">]å�4his() pure is called <ztpan>C m = <span class="d_keyword">new<ztpan> C([1,�(l4�)�5p¹); �!�!span class="d_comment">/Xëthis(int[]) immutable pure is called <ztpan></pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="field-init" href="#field-init">Field initialization inside a constructor<tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>In a constructor body,�4he first instance of field assignment is its initialization. �!�!y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> C { �!�!span class="d_keyword">int</span> num; �!�!span class="d_keyword">this<ztpan>() " num = 1; �!�!span class="d_comment">/Xëinitialization <ztpan> num = �([f�) <span class="d_comment">]å assignment </span> �( } <y:re> <div class="blankline"><u(iv> �!�!p>If�4he field�4ype has an�!�!a href="operatoroverloading.html#assignment"><span class="d_inlinecode donthyphenate notranslate">opAssign</span><tæ> method, it will not be used for initialization.</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">struct<ztpan> A { �!�!span class="d_keyword">this<ztpan>(<span class="d_keyword">int</span> n)"} <span class="d_keyword">void</span> <b><i>opAssign</i></b>(A rhs) {} } <span class="d_keyword">class</span> C { A val; �!�!span class="d_keyword">this<ztpan>() " �6al = A(1); <span class="d_comment">]å�6al is initialized to�4he�6alue of A(1) <ztpan> val = A(�(SA�); �!�!span class="d_comment">/Xërewritten to�6al.opAssign(A(�(SA�)) </span> �( } <y:re> <div class="blankline"><u(iv> <p>If the field type is not mutable, multiple initialization�7ill be rejected.</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">immutable<ztpan>�!�!span class="d_keyword">int</span> num; �!�!span class="d_keyword">this<ztpan>() " num = 1; �!�!span class="d_comment">/XëOK <ztpan> num = �([f�) <span class="d_comment">]å Error: multiple field initialization </span> �( } <y:re> <div class="blankline"><u(iv> <p>If the field is initialized on one path, it must be initialized on all paths.</p> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">immutable<ztpan>�!�!span class="d_keyword">int</span> num; �!�!span class="d_keyword">immutable</span> <span class="d_keyword">int<ztpan> ber; <span class="d_keyword">this</span>(<span class="d_keyword">int<ztpan> i) { <span class="d_keyword">if</span> (i) num = 0Ú0ü0¸ �!�!span class="d_comment">/Xëinitialization <ztpan> <span class="d_keyword">else</span> num = 4; �!�!span class="d_comment">/Xëinitialization <ztpan> } <span class="d_keyword">this</span>(<span class="d_keyword">long</span> j) " j ? (num = 0Î0Ã0È : (num = 4); <span class="d_comment">]å ok </span> j�=| (ber = 2 2); <span class="d_comment">]å error, intialized on only one�0ath </span> j�.�.�.amp;& (ber = 2 2); <span class="d_comment">]å error, intialized on only one�0ath </span> �( } <y:re> <div class="blankline"><u(iv> <p>A field initialization may not appear in a loop or after a label.</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> C { <span class="d_keyword">immutable<ztpan>�!�!span class="d_keyword">int</span> num; �!�!span class="d_keyword">immutable</span> string str; <span class="d_keyword">this</span>() { <span class="d_keyword">foreach<ztpan> (i; 0..�(SA�) " num = 1; �!�!span class="d_comment">/XëError: field initialization not allowed in loops <ztpan> } size_t i = 0; Label: str =�!�!span class="d_string">"hello"<ztpan>; �!�!span class="d_comment">/XëError: field initialization not allowed after labels <ztpan> <span class="d_keyword">if</span> (i++�.�.�.lt; �(SA�) �!�!span class="d_keyword">goto<ztpan> Label; } } </pre> <div class="blankline"></div> �!�!p>If a field's�4ype has disabled default construction,�4hen it must be initialized in the constructor.</p> <pre class="d_code notranslate"><span class="d_keyword">struct<ztpan> S"�!�!span class="d_keyword">int</span> y; @disable <span class="d_keyword">this</span>();�( <span class="d_keyword">class<ztpan> C { S s; <span class="d_keyword">this</span>(S t)" s =�4; } �!�!span class="d_comment">/Xëok <ztpan> <span class="d_keyword">this</span>(<span class="d_keyword">int<ztpan> i) { <span class="d_keyword">this</span>();�(�!�!span class="d_comment">/Xëok <ztpan> <span class="d_keyword">this</span>() { } �!�!span class="d_comment">/Xëerror, s not initialized <ztpan>} </pre> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="destructors" href="#destructors">Destructors<tæ><vv�(ŒÇ�) <div class="blankline"></div> <pre class="bnf notranslate"><a id="Destructor"><span class="gname">Destructor<ztpan></a>: <span class="d_inlinecode donthyphenate notranslate">~�4his ( )<ztpan>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#FunctionBody"><i>FunctionBody</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">~ this ( )</span> <a href="../specu‹unction.html#MemberFunctionAttributes"><i>MemberFunctionAttributes</i></a><sub>opt</sub>�!�!a href="..ztpec/function.html#MissingFunctionBody"><i>MissingFunctionBody<v}><tæ> </pre> <div class="blankline"></div> �!�!p>The destructor function is called when:<y:> <ul><li>A live object is deleted by�4he garbage collector</li> <li>A live�!�!a href="..ztpec/attribute.html#scope-class-var"><span class="d_inlinecode donthyphenate notranslate">scope</span> class instance</a> goes out of scope</li> <li><a href="../phoboswóbject.html#.destroy""><span class="d_inlinecode donthyphenate notranslate">destroy</span><tæ> is called on�4he object </li> </ul> <p>Example:<y:> <div class="blankline"><u(iv> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">import</span> std.stdio; <span class="d_keyword">class<ztpan> Foo { �)<span class="d_keyword">this</span>() <span class="d_comment">]å destructor for Foo </span> " �7riteln(<span class="d_string">"dtor"</span>); } } <span class="d_keyword">void<ztpan> main() { <span class="d_keyword">auto</span> foo = <span class="d_keyword">new<ztpan> Foo; destroy(foo); writeln(<span class="d_string">"end"</span>); } </pre> � </div> <ul><li>Only one destructor can be declared per class, although other destructors <a href="../speczËemplate-mixin.html#destructors">can be mixed in<tæ>.</li> <li>A destructor does not have any�0arameters or attributes.</li> <li>A destructor is always�6irtual. </li> </ul> <p>The destructor is expected to release any non-GC resources held by the object. </p> <div class="blankline"></div> �!�!p>The program can explicitly call the destructor of a live object immediately with�!�!a href="..y:hobos/object.html#.destroy""><span class="d_inlinecode donthyphenate notranslate">destroy<ztpan></a>. The runtime marks the object so the destructor is never called�4wice. </p> <div class="blankline"></div> �!�!p>The destructor for�4he�!�!a href="#super_class">super class<tæ> automatically gets called when �4he destructor ends. There is no way to call the super class destructor explicitly. �!�!y:> <div class="blankline"><u(iv> <div class="spec-boxes implementation-defined"><b>Implementation Defined:<u> The garbage collector is not guaranteed to run�4he destructor for all unreferenced objects.<u(iv> <div class="blankline"><u(iv> <div class="panel"> �!�!div class="spec-boxes"><b>Important:</b> The order in which the garbage collector calls destructors for unreferenced objects is not specified. This means that �7hen the garbage collector calls a destructor for an object of a class that has members�7hich are references to garbage collected objects, those references may no longer be valid. This means that destructors cannot reference sub objects.</div> <div class="blankline"></div> �!�!div class="spec-boxes note"><b>Note:</b> This rule does not apply to a�!�!span class="d_inlinecode donthyphenate notranslate">scope<ztpan> class instance or an object destructed with�!�!span class="d_inlinecode donthyphenate notranslate">destroy<ztpan>, as�4he destructor is not being run during a garbage collection cycle, meaning all references are�6alid.<u(iv> </div> <div class="blankline"></div> �!�!p>Objects referenced from the static data segment never get collected by�4he�?�?C. �!�!y:> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="static-ctor-dtor" href="#static-ctor-dtor">Static Constructors and Destructors</a></h2> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="static-constructor" href="#static-constructor">Static Constructors</a></h3> <div class="blankline"><u(iv> <pre class="bnf notranslate"><a id="StaticConstructor"><span class="gname">StaticConstructor</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">static�4his ( )<ztpan>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#FunctionBody"><i>FunctionBody</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">static�4his ( )<ztpan>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#MissingFunctionBody"><i>MissingFunctionBody</i></a> <y:re> <div class="blankline"><u(iv> <p>A static constructor is a function that�0erforms initializations of �4hread local data before the <span class="d_inlinecode donthyphenate notranslate">main()<ztpan> function gets control for�4he main thread, and upon�4hread startup.</p> <div class="blankline"></div> �!�!p>Static constructors are used�4o initialize static class members with �6alues that cannot be computed at compile�4ime.</p> <div class="blankline"></div> �!�!div class="panel"> Static constructors in other languages are built implicitly by�5sing member initializers�4hat can't be computed at compile�4ime. The�4rouble�7ith this stems from not having good control over exactly�7hen the code is executed, for example: <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { <span class="d_keyword">static</span> <span class="d_keyword">int<ztpan> a = b + 1; <span class="d_keyword">static</span> <span class="d_keyword">int<ztpan> b = a * 2; } </pre> <div class="blankline"></div> 2 2 2 2hat values do <span class="d_inlinecode donthyphenate notranslate">a</span> and <span class="d_inlinecode donthyphenate notranslate">b</span> end up�7ith,�7hat order are the initializations executed in,�7hat are the values of <span class="d_inlinecode donthyphenate notranslate">a</span> and <span class="d_inlinecode donthyphenate notranslate">b</span> before�4he initializations are run, is�4his a compile error, or is�4his a runtime error? Additional confusion comes from it not being obvious if an initializer is static or dynamic. <div class="blankline"><u(iv> <p>D makes�4his simple. All member initializations must be determinable by �4he compiler at compile�4ime, hence�4here is no order-af-evaluation dependency for member initializations, and it is not possible�4o read a�6alue�4hat has not been initialized. Dynamic initialization is performed by a static constructor, defined�7ith a special syntax�!�!span class="d_inlinecode donthyphenate notranslate">static�4his()<ztpan>.<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> Foo { �!�!span class="d_keyword">static<ztpan>�!�!span class="d_keyword">int</span> a; �!�!span class="d_comment">/Xëdefault initialized to 0 <ztpan> <span class="d_keyword">static</span> <span class="d_keyword">int<ztpan> b = 1; <span class="d_keyword">static</span> <span class="d_keyword">int<ztpan> c = b + a; <span class="d_comment">]å error, not a constant initializer <ztpan> �!�!b><i><span class="d_keyword">static<ztpan>�!�!span class="d_keyword">this<ztpan></i></b>() <span class="d_comment">]å static constructor </span> " a = b + 1; �!�!span class="d_comment">/Xëa is set�4o �(�)</span> b = a * 2; �!�!span class="d_comment">/Xëb is set�4o 4 </span> �( } <y:re> </div> <div class="blankline"></div> <p>If�!�!span class="d_inlinecode donthyphenate notranslate">main()</span> or�4he�4hread returns normally, (does not throw an exception),�4he static destructor is added to�4he list of functions�4o be called on�4hread termination.</p> <div class="blankline"></div> <p>Static constructors have empty�0arameter lists.<y:> <div class="blankline"><u(iv> <p> Static constructors�7ithin a module are executed in�4he lexical order in which they appear. All�4he static constructors for modules�4hat are directly or indirectly imported are executed before the static constructors for the importer. </p> <div class="blankline"></div> �!�!p> The <span class="d_inlinecode donthyphenate notranslate">static<ztpan> in the static constructor declaration is not an attribute, it must appear immediately before the <span class="d_inlinecode donthyphenate notranslate">this<ztpan>: </p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { <span class="d_keyword">static</span> <span class="d_keyword">this</span>() { ... } <span class="d_comment">]å a static constructor </span> �!�!span class="d_keyword">static<ztpan>�!�!span class="d_keyword">private</span> <span class="d_keyword">this</span>() { ... } <span class="d_comment">]å Error: not a static constructor <ztpan> <span class="d_keyword">static</span> { <span class="d_keyword">this</span>() { ... } �!�!span class="d_comment">/Xënot a static constructor <ztpan> } <span class="d_keyword">static</span>: �!�!span class="d_keyword">this<ztpan>()" ...�( <span class="d_comment">]å not a static constructor </span>} <y:re> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="static-destructor" href="#static-destructor">Static Destructors<tæ><vv0Ü0ë0È <div class="blankline"></div> <pre class="bnf notranslate"><a id="StaticDestructor"><span class="gname">StaticDestructor<ztpan></a>: <span class="d_inlinecode donthyphenate notranslate">static ~ this ( )</span> <a href="../specu‹unction.html#MemberFunctionAttributes"><i>MemberFunctionAttributes</i></a><sub>opt</sub>�!�!a href="..ztpec/function.html#FunctionBody"><i>FunctionBody<v}><tæ> </pre> <div class="blankline"></div> A static destructor is defined as a special static function�7ith the syntax�!�!span class="d_inlinecode donthyphenate notranslate">static�)this()</span>. <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { <span class="d_keyword">static</span> ~<span class="d_keyword">this<ztpan>()�!�!span class="d_comment">/Xëstatic destructor </span> " �( } <y:re> <div class="blankline"><u(iv> <p> A static destructor gets called on thread�4ermination, but only if the static constructor completed successfully. Static destructors have empty�0arameter lists. Static destructors get called in�4he reverse order�4hat the static constructors were called in. </p> <div class="blankline"></div> �!�!p> The <span class="d_inlinecode donthyphenate notranslate">static<ztpan> in the static destructor declaration is not an attribute, it must appear immediately before�4he�!�!span class="d_inlinecode donthyphenate notranslate">~this<ztpan>: </p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { <span class="d_keyword">static</span> ~<span class="d_keyword">this<ztpan>()" ...�( <span class="d_comment">]å a static destructor <ztpan> <span class="d_keyword">static</span> <span class="d_keyword">private<ztpan>�)<span class="d_keyword">this</span>() { ... } <span class="d_comment">]å Error: not a static destructor </span> �!�!span class="d_keyword">static<ztpan> " �)<span class="d_keyword">this</span>() { ... } �!�!span class="d_comment">/Xënot a static destructor </span> �( �!�!span class="d_keyword">static<ztpan>: ~<span class="d_keyword">this<ztpan>()" ...�( <span class="d_comment">]å not a static destructor <ztpan>} </pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="shared_static_constructors" href="#shared_static_constructors">Shared Static Constructors</a></h3> <div class="blankline"><u(iv> <pre class="bnf notranslate"><a id="SharedStaticConstructor"><span class="gname">SharedStaticConstructor</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">shared static this ( )</span> <a href="../specu‹unction.html#MemberFunctionAttributes"><i>MemberFunctionAttributes</i></a><sub>opt</sub>�!�!a href="..ztpec/function.html#FunctionBody"><i>FunctionBody<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">shared static�4his ( )<ztpan>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#MissingFunctionBody"><i>MissingFunctionBody</i></a> <y:re> <div class="blankline"><u(iv> <p>Shared static constructors are executed before any <a href="#StaticConstructor"><i>StaticConstructor<v}><tæ>s, and are intended for initializing any shared global data. </p> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="shared_static_destructors" href="#shared_static_destructors">Shared Static Destructors<tæ><vv0Ü0ë0È <div class="blankline"></div> <pre class="bnf notranslate"><a id="SharedStaticDestructor"><span class="gname">SharedStaticDestructor<ztpan></a>: <span class="d_inlinecode donthyphenate notranslate">shared static�)�4his ( )<ztpan>�!�!a href="..ztpec/function.html#MemberFunctionAttributes"><i>MemberFunctionAttributes<v}><tæ><sub>opt<ztub> <a href="../specu‹unction.html#FunctionBody"><i>FunctionBody</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">shared static ~ this ( )</span> <a href="../specu‹unction.html#MemberFunctionAttributes"><i>MemberFunctionAttributes</i></a><sub>opt</sub>�!�!a href="..ztpec/function.html#MissingFunctionBody"><i>MissingFunctionBody<v}><tæ> </pre> <div class="blankline"></div> �!�!p>Shared static destructors are executed at program termination in�4he reverse order�4hat <a href="#SharedStaticConstructor"><i>SharedStaticConstructor<v}><tæ>s�7ere executed. </p> <div class="blankline"></div> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="invariants" href="#invariants">Class Invariants</a></h2> <div class="blankline"><u(iv> <pre class="bnf notranslate"><a id="Invariant"><span class="gname">Invariant</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">invariant ( )<ztpan>�!�!a href="..ztpec/statement.html#BlockStatement"><i>BlockStatement</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">invariant<ztpan>�!�!a href="..ztpec/statement.html#BlockStatement"><i>BlockStatement</i></a> �!�!span class="d_inlinecode donthyphenate notranslate">invariant (<ztpan>�!�!a href="..ztpec/expression.html#AssertArguments"><i>AssertArguments<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">)�<�s�p�a�n� �c�l�a�s�s�=�"�n�a�k�e�d�_�s�i�g�n�"�> ;�<�/�s�p�a�n�>�<�s�p�a�n� �c�l�a�s�s�=�"�n�a�k�e�d�_�a�u�r�a�l�"�>�(lèŠ�)�<�/�s�p�a�n�></span> </pre> <div class="blankline"></div> �!�!p>Class <i>Invariant</i>s specify the relationships among the members of a class instance. Those relationships must hold for any interactions with�4he instance from its �0ublic interface. �!�!y:> <div class="blankline"><u(iv> <p>The invariant is in�4he form of a�!�!span class="d_inlinecode donthyphenate notranslate">const<ztpan> member function. The invariant is defined �4o <i>hold<v}> if all�4he�!�!a href="..ztpec/expression.html#AssertExpression"><i>AssertExpression<v}><tæ>s�7ithin the invariant that are executed succeed. �!�!y:> <div class="blankline"><u(iv> <div class="runnable-examples" data-compile=''> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> Date { <span class="d_keyword">this</span>(<span class="d_keyword">int<ztpan> d, <span class="d_keyword">int<ztpan> h) { day = d; <span class="d_comment">]å days are 1..31 </span> hour = h; �!�!span class="d_comment">/Xëhours are 0..20ª0ü0à</span> �( <span class="d_keyword">invariant<ztpan> " �!�!span class="d_keyword">assert<ztpan>(1�.�.�.lt;= day�.�.�.amp;& day <= 0Ó0ë); �!�!span class="d_keyword">assert<ztpan>(0�.�.�.lt;= hour && hour < 24); } �!�!span class="d_keyword">private</span>: �!�!span class="d_keyword">int</span> day; �!�!span class="d_keyword">int</span> hour; } </pre> � </div> <div class="blankline"></div> �!�!p>Any class invariants for base classes are applied before�4he class invariant for�4he derived class.<y:> <div class="blankline"><u(iv> <p>There may be multiple invariants in a class. They are applied in lexical order.</p> <div class="blankline"></div> �!�!p>Class <i>Invariant</i>s must hold at�4he exit of�4he class constructor (if any), and at the entry of�4he class destructor (if any).<y:> <div class="blankline"><u(iv> <p>Class�!�!i>Invariant<v}>s must hold at the entry and exit of all public or exported non-static member functions. The order of application of invariants is:</p> �!�!ol> �!�!li>preconditions</li> <li>invariant<vîi> �!�!li>function body</li> <li>invariant<vîi> �!�!li>postconditions<vîi> �!�!wól> <div class="blankline"></div> �!�!p>If�4he invariant does not hold, then�4he�0rogram enters an invalid state.<y:> <div class="blankline"><u(iv> <div class="spec-boxes implementation-defined"><b>Implementation Defined:<u> <ol> <li>Whether the class <i>Invariant</i> is executed at runtime or not. This is typically controlled�7ith a compiler switch.</li> <li>The behavior�7hen the invariant does not hold is�4ypically�4he same as for�7hen <a href="../specu0xpression.html#AssertExpression"><i>AssertExpression</i></a>s fail.<vîi> �!�!wól> �!�!u(iv> <div class="blankline"><u(iv> <div class="spec-boxes�5ndefined-behavior"><b>Undefined Behavior:<u> happens if�4he invariant does not hold and execution continues.<u(iv> <div class="blankline"><u(iv> <p>Public or exported non-static member functions cannot be called from within an invariant.</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Foo { <span class="d_keyword">public</span> <span class="d_keyword">void</span> f() { } <span class="d_keyword">private<ztpan>�!�!span class="d_keyword">void<ztpan> g()"�( <span class="d_keyword">invariant<ztpan> " f(); �!�!span class="d_comment">/Xëerror, cannot call�0ublic member function from invariant <ztpan> g(); <span class="d_comment">]å ok, g() is not public <ztpan> } } </pre> <div class="blankline"></div> �!�!div class="spec-boxes best-practice"><b>Best Practices:<u> <ol> <li>Do not indirectly call exported or�0ublic member functions�7ithin a class invariant, as this can result in infinite recursion.</li> <li>Avoid reliance on side effects in the invariant. as the invariant may or may not be executed.<vîi> �!�!li>Avoid having mutable public fields of classes�7ith invariants, as�4hen the invariant cannot�6erify the public interface.<vîi> �!�!wól> �!�!u(iv> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="auto" href="#auto">Scope Classes</a></h2> <div class="spec-boxes note"><b>Note:<u> Scope classes have been <a href="../deprecate.html#scope as a type constraint"> deprecated</a>. See also <a href="..ztpec/attribute.html#scope-class-var"><span class="d_inlinecode donthyphenate notranslate">scope</span> class instances<tæ>.</div> <div class="blankline"></div> �!�!p>A scope class is a class�7ith the <span class="d_inlinecode donthyphenate notranslate">scope</span> attribute, as in:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">scope<ztpan>�!�!span class="d_keyword">class</span> Foo { ... } </pre> <div class="blankline"></div> <p>The scope characteristic is inherited, so any classes derived from a scope class are also scope.</p> <div class="blankline"></div> �!�!p>A scope class reference can only appear as a function local variable. It must be declared as being�!�!span class="d_inlinecode donthyphenate notranslate">scope<ztpan>:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">scope<ztpan>�!�!span class="d_keyword">class</span> Foo { ... } <span class="d_keyword">void<ztpan> func() { Foo f; <span class="d_comment">]å error, reference to scope class must be scope <ztpan> <span class="d_keyword">scope<ztpan> Foo g =�!�!span class="d_keyword">new</span> Foo();�!�!span class="d_comment">/Xëcorrect </span>} <y:re> <div class="blankline"><u(iv> <p>When a scope class reference goes out of scope,�4he destructor (if any) for it is automatically called. This holds true even if�4he scope�7as exited via a thrown exception.<y:> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="abstract" href="#abstract">Abstract Classes<tæ><vv�(ŒÇ�) <div class="blankline"></div> <p> An abstract member function must be overridden by a derived class. Only virtual member functions may be declared abstract; non-virtual member functions and free-standing functions cannot be declared abstract. <y:> <div class="blankline"><u(iv> <p> A class is abstract if any of its�6irtual member functions are declared abstract or if they are defined�7ithin an abstract attribute. Note that an abstract class may also contain non-virtual member functions. Abstract classes cannot be instantiated directly. They can only be instantiated as a base class of another, non-abstract, class. <y:> <div class="blankline"><u(iv> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> C { �!�!span class="d_keyword">abstract<ztpan>�!�!span class="d_keyword">void<ztpan> f(); } <span class="d_keyword">auto<ztpan> c =�!�!span class="d_keyword">new</span> C;�!�!span class="d_comment">/Xëerror, C is abstract <ztpan> <span class="d_keyword">class</span> D : C {} <span class="d_keyword">auto</span> d = <span class="d_keyword">new<ztpan> D; <span class="d_comment">]å error, D is abstract </span> <span class="d_keyword">class<ztpan> E : C { �!�!span class="d_keyword">override<ztpan>�!�!span class="d_keyword">void<ztpan> f()"} } <span class="d_keyword">auto<ztpan> e =�!�!span class="d_keyword">new</span> E;�!�!span class="d_comment">/XëOK <ztpan></pre> </div> <div class="blankline"></div> <p> Member functions declared as abstract can still have function bodies. This is so�4hat even�4hough they must be overridden, �4hey can still provide ‘base class functionality’, e.g.�4hrough�!�!a href="..ztpec/expression.html#super"><span class="d_inlinecode donthyphenate notranslate">super.foo()<ztpan></a> in a derived class. Note that�4he class is still abstract and cannot be instantiated directly. </p> <div class="blankline"></div> <p> A class can be declared abstract: </p> <div class="blankline"></div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">abstract<ztpan>�!�!span class="d_keyword">class</span> A { <span class="d_comment">]å ... <ztpan>} <span class="d_keyword">auto<ztpan> a =�!�!span class="d_keyword">new</span> A;�!�!span class="d_comment">/Xëerror, A is abstract <ztpan> <span class="d_keyword">class</span> B : A {} <span class="d_keyword">auto</span> b = <span class="d_keyword">new<ztpan> B; <span class="d_comment">]å OK </span><y:re> <u(iv> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="final" href="#final">Final Classes</a></h2> <div class="blankline"><u(iv> <p>Final classes cannot be subclassed:</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">final</span> <span class="d_keyword">class<ztpan> A"�( <span class="d_keyword">class</span> B : A { } �!�!span class="d_comment">/Xëerror, class A is final </span><y:re> <div class="blankline"><u(iv> <p>Methods of a final class are always �!�!a href="..ztpec/function.html#final"><span class="d_inlinecode donthyphenate notranslate">final<ztpan></a>.<y:> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="nested" href="#nested">Nested Classes<tæ><vv�(ŒÇ�) <div class="blankline"></div> <p>A <i>nested class<v}> is a class�4hat is declared inside�4he scope of a function or another class. A nested class has access�4o the variables and other symbols of�4he classes and functions it is nested inside:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> Outer { �!�!span class="d_keyword">int</span> m; <span class="d_keyword">class<ztpan>�!�?nner " �!�!span class="d_keyword">int</span> foo() { <span class="d_keyword">return</span> m; �!�!span class="d_comment">/XëOk�4o access member of Outer <ztpan> } } } </pre> <pre class="d_code notranslate"><span class="d_keyword">void<ztpan> func() { <span class="d_keyword">int<ztpan> m; �!�!span class="d_keyword">class</span> Inner { <span class="d_keyword">int<ztpan> foo() " �!�!span class="d_keyword">return<ztpan> m; <span class="d_comment">]å Ok to access local variable m of func() <ztpan> } } } </pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="static-nested" href="#static-nested">Static Nested Classes<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>If a nested class has the <span class="d_inlinecode donthyphenate notranslate">static<ztpan> attribute, then it can not access variables of the enclosing scope that are local�4o the stack or need a <span class="d_inlinecode donthyphenate notranslate">this<ztpan> reference:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> Outer { �!�!span class="d_keyword">int</span> m; �!�!span class="d_keyword">static<ztpan>�!�!span class="d_keyword">int</span> n; <span class="d_keyword">static</span> <span class="d_keyword">class<ztpan>�!�?nner " �!�!span class="d_keyword">int</span> foo() { <span class="d_keyword">return</span> m; �!�!span class="d_comment">/XëError,�!�?nner is static and m needs a�4his </span> �!�!span class="d_keyword">return<ztpan> n; <span class="d_comment">]å Ok, n is static <ztpan> } } } </pre> <pre class="d_code notranslate"><span class="d_keyword">void<ztpan> func() { <span class="d_keyword">int<ztpan> m; <span class="d_keyword">static</span> <span class="d_keyword">int<ztpan> n; �!�!span class="d_keyword">static<ztpan>�!�!span class="d_keyword">class</span> Inner { <span class="d_keyword">int<ztpan> foo() " �!�!span class="d_keyword">return<ztpan> m; <span class="d_comment">]å Error, Inner is static and m is local�4o the stack </span> �!�!span class="d_keyword">return<ztpan> n; <span class="d_comment">]å Ok, n is static <ztpan> } } } </pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="nested-context" href="#nested-context">Context Pointer<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>Non-static nested classes work by containing an extra hidden member (called the context pointer)�4hat is�4he frame�0ointer of the enclosing function if it is nested inside a function, or�4he�!�!span class="d_inlinecode donthyphenate notranslate">this</span> reference of�4he enclosing class's instance if it is nested inside a class.<y:> <div class="blankline"><u(iv> <p>When a non-static nested class is instantiated,�4he context�0ointer is assigned before the class's constructor is called,�4herefore �4he constructor has full access�4o the enclosing variables. A non-static nested class can only be instantiated when�4he necessary context�0ointer information is available:</p> <div class="blankline"></div> <div class="runnable-examples" data-compile=''> <pre class="d_code notranslate"><span class="d_keyword">class</span> Outer { <span class="d_keyword">class<ztpan>�!�?nner"�( <span class="d_keyword">static</span> <span class="d_keyword">class<ztpan> SInner { } } <span class="d_keyword">void<ztpan> main() { Outer o = <span class="d_keyword">new<ztpan> Outer; �!�!span class="d_comment">/XëOk <ztpan> <span class="d_comment">]åOuter.Inner oi = new Outer.Inner; ]å Error, no 'this' for Outer </span> Outer.SInner os =�!�!span class="d_keyword">new</span> Outer.SInner; <span class="d_comment">]å Ok </span>} <y:re> <u(iv> <div class="blankline"><u(iv> <div class="runnable-examples" data-compile=''> <pre class="d_code notranslate"><span class="d_keyword">void</span> main() { �!�!span class="d_keyword">class</span> Nested"�( Nested n =�!�!span class="d_keyword">new</span> Nested; �!�!span class="d_comment">/XëOk <ztpan> �!�!span class="d_keyword">static<ztpan> f() " �!�!span class="d_comment">/k³ested sn = new Nested;� XëError, no 'this' for Nested </span> �( } <y:re> <u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="nested-explicit" href="#nested-explicit">Explicit Instantiation<tæ><vv0Ü0ë0È <div class="blankline"></div> �!�!p>A <span class="d_inlinecode donthyphenate notranslate">this<ztpan> reference can be supplied�4o the creation of an inner class instance by�0refixing it to�4he�!�!i>NewExpression<v}>: �!�!y:> <div class="blankline"><u(iv> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> Outer { �!�!span class="d_keyword">int</span> a; <span class="d_keyword">class<ztpan>�!�?nner " �!�!span class="d_keyword">int</span> foo() { <span class="d_keyword">return</span> a; �( �( } <span class="d_keyword">void</span> main() { Outer o =�!�!span class="d_keyword">new</span> Outer; o.a = 2 2; Outer.Inner oi = o.<span class="d_keyword">new</span> Inner; �!�!span class="d_keyword">assert<ztpan>(oi.foo() == 2 2); } <y:re> <u(iv> <div class="blankline"><u(iv> <p>Here <span class="d_inlinecode donthyphenate notranslate">o</span> supplies�4he�!�!span class="d_inlinecode donthyphenate notranslate">this</span> reference to�4he inner class instance of�!�!span class="d_inlinecode donthyphenate notranslate">Outer<ztpan>. </p> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="outer-property" href="#outer-property"><span class="d_inlinecode donthyphenate notranslate">outer</span> Property</a></h3> <div class="blankline"><u(iv> <p>For a nested class instance, the <span class="d_inlinecode donthyphenate notranslate">.outer<ztpan>�0roperty provides �4he�!�!span class="d_inlinecode donthyphenate notranslate">this</span> reference of�4he enclosing class's instance. �!�?f there is no accessible�0arent class instance, the property �0rovides a <span class="d_inlinecode donthyphenate notranslate">void*</span> to�4he enclosing function frame.</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">class</span> Outer { <span class="d_keyword">class<ztpan>�!�?nner1 { Outer getOuter() " �!�!span class="d_keyword">return<ztpan>�!�!span class="d_keyword">this<ztpan>.<b><i>outer</i></b>; } } �!�!span class="d_keyword">void<ztpan> foo() " �!�?nner1 i = <span class="d_keyword">new<ztpan>�!�?nner± �!�!span class="d_keyword">assert<ztpan>(i.getOuter() <span class="d_keyword">is</span> <span class="d_keyword">this</span>); } } </pre> <pre class="d_code notranslate"><span class="d_keyword">class</span> Outer { <span class="d_keyword">void</span> bar() { <span class="d_comment">]å�8 is referenced from nested scope, so <ztpan> <span class="d_comment">]å bar makes a closure environment. </span> �!�!span class="d_keyword">int</span> x = ± <span class="d_keyword">class<ztpan>�!�?nner�(�) { Outer getOuter() " �8 = 2; <span class="d_comment">]å The�!�?nner�(N��)instance has access to�4he function frame </span> �!�!span class="d_comment">/Xëof bar as a static frame�0ointer, but .outer returns <ztpan> <span class="d_comment">]å�4he enclosing Outer class instance property. </span> �!�!span class="d_keyword">return<ztpan>�!�!span class="d_keyword">this<ztpan>.<b><i>outer</i></b>; } } �!�?nner�(N��)i = <span class="d_keyword">new<ztpan>�!�?nner�([f�) �!�!span class="d_keyword">assert<ztpan>(i.getOuter() <span class="d_keyword">is</span> <span class="d_keyword">this</span>); } } </pre> <pre class="d_code notranslate"><span class="d_keyword">class</span> Outer { <span class="d_comment">]å baz cannot access an instance of Outer </span> �!�!span class="d_keyword">static<ztpan>�!�!span class="d_keyword">void<ztpan> baz() " �!�!span class="d_comment">/Xëmake a closure environment <ztpan> <span class="d_keyword">int<ztpan>�8 = 1; �!�!span class="d_keyword">class</span> Inner3 " �!�!span class="d_keyword">void<ztpan>* getOuter() " �8 = 2; <span class="d_comment">]å There's no accessible enclosing class instance, so the </span> �!�!span class="d_comment">/Xë.outer�0roperty returns the function frame of baz. <ztpan> <span class="d_keyword">return</span> <span class="d_keyword">this</span>.<b><i>outer<v}><u>; �( �( Inner3 i =�!�!span class="d_keyword">new</span> Inner3; <span class="d_keyword">assert</span>(i.getOuter() !<span class="d_keyword">is</span> <span class="d_keyword">null</span>); } } </pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="anonymous" href="#anonymous">Anonymous Nested Classes</a></h3> <div class="blankline"><u(iv> <p>An anonymous nested class is both defined and instantiated with a�!�!i>NewAnonClassExpression</i>: </p> <div class="blankline"></div> <pre class="bnf notranslate"><a id="NewAnonClassExpression"><span class="gname">NewAnonClassExpression<ztpan></a>: <span class="d_inlinecode donthyphenate notranslate">new</span> <span class="d_inlinecode donthyphenate notranslate">class</span> <a href="#ConstructorArgs"><i>ConstructorArgs<v}><tæ><sub>opt<ztub> <a href="#AnonBaseClassList"><i>AnonBaseClassList<v}><tæ><sub>opt<ztub> <a href="../speczttruct.html#AggregateBody"><i>AggregateBody</i></a> <div class="blankline"></div> <a id="ConstructorArgs"><span class="gname">ConstructorArgs</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">(<ztpan>�!�!a href="..ztpec/expression.html#NamedArgumentList"><i>NamedArgumentList<v}><tæ><sub>opt<ztub> <span class="d_inlinecode donthyphenate notranslate">)</span> <div class="blankline"><u(iv> <a id="AnonBaseClassList"><span class="gname">AnonBaseClassList<ztpan></a>: <a href="#SuperClassOrInterface"><i>SuperClassOrInterface<v}><tæ> <a href="#SuperClassOrInterface"><i>SuperClassOrInterface<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">,</span> <a href="#Interfaces"><i>Interfaces<v}><tæ> </pre> <div class="blankline"></div> which is equivalent�4o: <div class="blankline"></div> <pre class="bnf notranslate"><span class="d_inlinecode donthyphenate notranslate">class</span> <a href="../specvîex.html#Identifier"><i>Identifier<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">:</span> <i>AnonBaseClassList</i>�!�!i>AggregateBody<v}> ]å ... <span class="d_inlinecode donthyphenate notranslate">new<ztpan>�!�!i>Identifier</i>�!�!i>ConstructorArgs<v}> </pre> <div class="blankline"></div> where�!�!i>Identifier</i> is the name generated for�4he anonymous nested class. <div class="blankline"></div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">interface</span> I { <span class="d_keyword">void</span> foo(); } <span class="d_keyword">auto</span> obj = <span class="d_keyword">new<ztpan>�!�!span class="d_keyword">class</span> I { <span class="d_keyword">void</span> foo() { writeln(<span class="d_string">"foo"</span>); } }; obj.foo(); </pre> </div> <div class="blankline"></div> <h2><span id="ConstClass"><a class="anchor"�4itle="Permalink to�4his section" id="const-class" href="#const-class">Const,�!�?mmutable and Shared Classes<tæ><ztpan></h2><div class="blankline"></div> �!�!p>If a�!�!i>ClassDeclaration</i> has a�!�!span class="d_inlinecode donthyphenate notranslate">const<ztpan>, <span class="d_inlinecode donthyphenate notranslate">immutable</span> or�!�!span class="d_inlinecode donthyphenate notranslate">shared</span> storage class,�4hen it is as if each member of�4he class �7as declared with�4hat storage class. �!�?f a base class is const, immutable or shared, then all classes derived from it are also const, immutable or shared. </p> <div style="float: left"><i class="fa fa-angle-left" aria-hidden="true"><v}> <a href="../speczttruct.html">Structs and Unions</a></div> <div style="float: right"><a href="..ztpec/interface.html">Interfaces</a>�!�!i class="fa fa-angle-right" aria-hidden="true"><v}><u(iv> <div style="clear:both"></div> <div class="smallprint" id="copyright">Copyright�.�.�.copy; 99-2025 by�4he�!�!a href="..u‹oundation_overview.html">D Language Foundation</a>�= Page generated by <a href="..ztpec/ddoc.html">Ddoc<tæ> on Fri Oct 10 �(g �):16:57 2025 �<u(iv> </div> <u(iv> �!�!script�4ype="text/javascript" src="https:/tæjax.googleapis.comtæjax/libsv®query/1.7.�(W�)jquery.min.js"><ztcript> �!�!script�4ype="text/javascript">window.jQuery || document.write('\x3Cscript src="../jsv®query-1.7.�(‘Ñ�)min.js">\x0Þ0¤0¯0íztcript>');<ztcript> �!�!script�4ype="text/javascript" src="../jsu(lang.js"><ztcript> � <script type="textv®avascript" src="..v®s/codemirror-compressed.js"></script> <script type="textv®avascript" src="..v®s/run.js"></script> <script type="textv®avascript" src="..v®s/listanchors.js"></script> <script type="textv®avascript">jQuery(document).ready(addVersionSelector);</script> <link rel="stylesheet" href="https:/wÛaxcdn.bootstrapcdn.comu‹ont-awesome/4.4.0/css/font-awesome.min.css"> <uody> <vvtml>�<�/�d�i�v�>�<�d�i�v� �c�l�a�s�s�=�"�n�a�k�e�d�_�c�t�r�l�"�>� �<�f�o�r�m� �a�c�t�i�o�n�=�"�/�i�n�d�e�x�.�c�g�i�/�l�a�r�g�e�r�-�t�e�x�t�"� �m�e�t�h�o�d�=�"�g�e�t�"� �n�a�m�e�=�"�g�a�t�e�"�>� �<�p�>�<�a� �h�r�e�f�=�"�h�t�t�p�:�/�/�a�l�t�s�t�y�l�e�.�a�l�f�a�s�a�d�o�.�n�e�t�"�>�A�l�t�S�t�y�l�e�<�/�a�>� 0k0ˆ0c0fY cÛ0U0Œ0_0Ú0ü0¸� �<�a� �h�r�e�f�=�"�h�t�t�p�s�:�/�/�d�l�a�n�g�.�o�r�g�/�s�p�e�c�/�c�l�a�s�s�.�h�t�m�l�"�>�(�-�&�g�t�;0ª0ê0¸0Ê0ë�)�<�/�a�>� �/� �<�l�a�b�e�l�>0¢0É0ì0¹�:� �<�i�n�p�u�t� �t�y�p�e�=�"�t�e�x�t�"� �n�a�m�e�=�"�n�a�k�e�d�_�p�o�s�t�_�u�r�l�"� �v�a�l�u�e�=�"�h�t�t�p�s�:�/�/�d�l�a�n�g�.�o�r�g�/�s�p�e�c�/�c�l�a�s�s�.�h�t�m�l�"� �s�i�z�e�=�"�2�2�"� �/�>�<�/�l�a�b�e�l�>� �<�l�a�b�e�l�>0â0ü0É�:� �<�s�e�l�e�c�t� �n�a�m�e�=�"�n�a�k�e�d�_�p�o�s�t�_�m�o�d�e�"�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�d�e�f�a�u�l�t�"�>0Ç0Õ0©0ë0È�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�s�p�e�e�c�h�"�>—óXð0Ö0é0¦0¶�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�r�u�b�y�"�>0ë0ÓNØ0M�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�c�o�n�t�r�a�s�t�"�>‘M‚rSÍŽâ�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�l�a�r�g�e�r�-�t�e�x�t�"� �s�e�l�e�c�t�e�d�=�"�s�e�l�e�c�t�e�d�"�>e‡[WbáY'�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�m�o�b�i�l�e�"�>0â0Ð0¤0ë�<�/�o�p�t�i�o�n�>� �<�/�s�e�l�e�c�t�>� �<�i�n�p�u�t� �t�y�p�e�=�"�s�u�b�m�i�t�"� �v�a�l�u�e�=�"ˆhy:�"� �/�>� �<�/�p�>� �<�/�f�o�r�m�>� �<�/�d�i�v�>� � �