<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Extern on Cheat Sheet</title><link>/tags/extern/</link><description>Recent content in Extern on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/extern/index.xml" rel="self" type="application/rss+xml"/><item><title>C++ Keywords Reference</title><link>/programming/cpp/keywords/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/cpp/keywords/</guid><description>&lt;h1 id="c-keywords-reference"&gt;C++ Keywords Reference&lt;a class="anchor" href="#c-keywords-reference"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This post consolidates core C++ and Modern C++ (C++11+) keywords, organized by role.&lt;/p&gt;
&lt;h3 id="anatomy-of-keyword-placement-in-a-function-declaration"&gt;Anatomy of Keyword Placement in a Function Declaration&lt;a class="anchor" href="#anatomy-of-keyword-placement-in-a-function-declaration"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Keywords attached to a C++ function declaration are placed into &lt;strong&gt;Declaration Specifiers (prefix) / Function Qualifiers &amp;amp; Specifiers (after &lt;code&gt;()&lt;/code&gt;) / Function Body (at the end)&lt;/strong&gt; according to the C++ grammar and compiler parsing order:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;virtual const int&amp;amp; FUNCTION(PARAM_TYPE PARAM_NAME) const &amp;amp; noexcept = 0;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;─────── ────────── ─────────────────────────────── ──────────────── ───
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │ │ │ │ └─ Function Body: { ... }, = default, = delete, = 0
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │ │ │ └─ Function Qualifiers &amp;amp; Specifiers: const/volatile, &amp;amp;/&amp;amp;&amp;amp;, noexcept, override, final
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │ │ └─ Function Name(Params)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │ └─ Return Type (prefix const = const return value)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; └─ Declaration Specifiers: explicit, virtual, inline, static, constexpr&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;1. Declaration Specifiers (before function: &lt;code&gt;explicit&lt;/code&gt;, &lt;code&gt;virtual&lt;/code&gt;, &lt;code&gt;inline&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt;, &lt;code&gt;constexpr&lt;/code&gt;):&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Declare &lt;strong&gt;how the function is linked, inlined, or invoked&lt;/strong&gt; before reaching the function name, independent of its parameters or body.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;2. Function Qualifiers &amp;amp; Specifiers (after &lt;code&gt;()&lt;/code&gt;: &lt;code&gt;const&lt;/code&gt;/&lt;code&gt;volatile&lt;/code&gt;, &lt;code&gt;&amp;amp;&lt;/code&gt;/&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;noexcept&lt;/code&gt;, &lt;code&gt;override&lt;/code&gt;, &lt;code&gt;final&lt;/code&gt;):&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Avoiding Return-Type Ambiguity (&lt;code&gt;const&lt;/code&gt;, &lt;code&gt;&amp;amp;&lt;/code&gt; / &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;):&lt;/strong&gt; Writing &lt;code&gt;const&lt;/code&gt; or &lt;code&gt;&amp;amp;&lt;/code&gt;/&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; in front (&lt;code&gt;const int&amp;amp; func()&lt;/code&gt;) qualifies the &lt;strong&gt;return type&lt;/strong&gt;, not the member function. Placing them after &lt;code&gt;()&lt;/code&gt; unambiguously qualifies the implicit &lt;code&gt;*this&lt;/code&gt; object&amp;rsquo;s constness (&lt;code&gt;const&lt;/code&gt;) and value category (&lt;code&gt;&amp;amp;&lt;/code&gt; = lvalue, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; = rvalue) &lt;em&gt;(see &lt;a href="../../programming/cpp/copy-elision-and-move-semantics/#6-ref-qualified-member-functions"&gt;Copy Elision &amp;amp; Move Semantics: Ref-qualified Member Functions&lt;/a&gt;)&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Referencing Parameter Scope (&lt;code&gt;noexcept&lt;/code&gt;):&lt;/strong&gt; The compiler parses left-to-right, and conditional exception specifications &lt;code&gt;noexcept(expr)&lt;/code&gt; &lt;strong&gt;must be able to reference parameter names&lt;/strong&gt; (e.g., &lt;code&gt;void f(T x) noexcept(x.is_safe())&lt;/code&gt;). Thus, &lt;code&gt;noexcept&lt;/code&gt; must appear after the parameter list &lt;code&gt;( ... )&lt;/code&gt; has been declared.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;3. Function Body &amp;amp; Pure Specifier (at the end after &lt;code&gt;=&lt;/code&gt;: &lt;code&gt;= default&lt;/code&gt;, &lt;code&gt;= delete&lt;/code&gt;, &lt;code&gt;= 0&lt;/code&gt;):&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Replacing &lt;code&gt;{ ... }&lt;/code&gt;:&lt;/strong&gt; These stand directly in place of the function body &lt;code&gt;{ ... }&lt;/code&gt; at the very end of the declaration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why &lt;code&gt;=&lt;/code&gt; is used:&lt;/strong&gt; Following the classic pure virtual syntax (&lt;code&gt;= 0&lt;/code&gt;), C++11 &lt;strong&gt;reused existing keywords (&lt;code&gt;default&lt;/code&gt; from &lt;code&gt;switch&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt; from memory deallocation) after &lt;code&gt;=&lt;/code&gt;&lt;/strong&gt; to avoid introducing new reserved words while clearly signaling a special function-body definition.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="1-special-member-function--conversion-control-keywords--default--delete-explicit-noexcept"&gt;1. Special Member Function &amp;amp; Conversion Control Keywords (&lt;code&gt;= default&lt;/code&gt;, &lt;code&gt;= delete&lt;/code&gt;, &lt;code&gt;explicit&lt;/code&gt;, &lt;code&gt;noexcept&lt;/code&gt;)&lt;a class="anchor" href="#1-special-member-function--conversion-control-keywords--default--delete-explicit-noexcept"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;These keywords control constructors, destructors, copy/move operations, and type conversions at compile time (see &lt;a href="../../programming/cpp/primer/copy-control/"&gt;Copy Control&lt;/a&gt; and &lt;a href="../../programming/cpp/copy-elision-and-move-semantics/"&gt;Copy Elision &amp;amp; Move Semantics&lt;/a&gt;).&lt;/p&gt;</description></item></channel></rss>