<!DOCTYPE html><html lang='en'><head><title>[basic.def]</title><meta charset='UTF-8'/><link rel='stylesheet' type='text/css' href='14882.css'/><link rel='stylesheet' type='text/css' href='expanded.css' title='Notes and examples expanded'/><link rel='alternate stylesheet' type='text/css' href='colored.css' title='Notes and examples colored'/><link rel='alternate stylesheet' type='text/css' href='collapsed.css' title='Notes and examples collapsed'/><link rel='icon' href='icon.png'/></head><body><div class='wrapper'><h1 ><a class='secnum' style='min-width:73pt'>6</a> Basics <a class='abbr_ref' href='./#basic'>[basic]</a></h1><h2 ><a class='secnum' style='min-width:88pt'>6.1</a> Declarations and definitions <a class='abbr_ref'>[basic.def]</a></h2><div class='para' id='1'><div class='marginalizedparent'><a class='marginalized' href='#1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/basic.tex#L94'>#</a></div><div id='1.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':declaration,definition_versus'></a></span><span class='indexparent'><a class='index' id=':declaration'></a></span><span class='indexparent'><a class='index' id=':declaration,name'></a></span>A <a href='dcl.dcl'>declaration</a> may introduce
one or more names into a translation
unit or redeclare names introduced by previous declarations<a class='hidden_link' href='#1.sentence-1'>.</a></div> <div id='1.sentence-2' class='sentence'>If so, the
declaration specifies the interpretation and attributes of these names<a class='hidden_link' href='#1.sentence-2'>.</a></div> <div id='1.sentence-3' class='sentence'>A declaration may also have effects including:
<ul class='itemize'><li id='1.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.1'>(1.1)</a></div><div id='1.1.sentence-1' class='sentence'>a <a href='dcl.dcl#:static_assert'>static assertion</a>,</div></li><li id='1.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.2'>(1.2)</a></div><div id='1.2.sentence-1' class='sentence'>controlling <a href='temp.explicit'>template instantiation</a>,</div></li><li id='1.3'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.3'>(1.3)</a></div><div id='1.3.sentence-1' class='sentence'>guiding template argument deduction for constructors (<a href='temp.deduct.guide'>[temp.deduct.guide]</a>),</div></li><li id='1.4'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.4'>(1.4)</a></div><div id='1.4.sentence-1' class='sentence'>use of <a href='dcl.attr'>attributes</a>, and</div></li><li id='1.5'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.5'>(1.5)</a></div><div id='1.5.sentence-1' class='sentence'>nothing (in the case of an <i ><a href='dcl.dcl#nt:empty-declaration'>empty-declaration</a></i>)<a class='hidden_link' href='#1.5.sentence-1'>.</a></div></li></ul></div></div><div class='para' id='2'><div class='marginalizedparent'><a class='marginalized' href='#2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/basic.tex#L112'>#</a></div><div id='2.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':declaration,function'></a></span><span class='indexparent'><a class='index' id=':definition'></a></span>Each entity declared by a <i ><a href='dcl.dcl#nt:declaration'>declaration</a></i> is
also <a class='hidden_link' href='#def:define' id='def:define'><i >defined</i></a> by that declaration unless:
<ul class='itemize'><li id='2.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.1'>(2.1)</a></div><div id='2.1.sentence-1' class='sentence'>it declares a function
without specifying the function's body (<a href='dcl.fct.def'>[dcl.fct.def]</a>),</div></li><li id='2.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.2'>(2.2)</a></div><div id='2.2.sentence-1' class='sentence'>it contains
the
<span class='indexparent'><a class='index' id=':declaration,extern'></a></span><a href='dcl.stc#:extern'><span class='texttt'>extern</span></a> specifier or a
<i ><a href='dcl.link#nt:linkage-specification'>linkage-specification</a></i><a class='footnotenum' href='#footnote-20'>20</a> (<a href='dcl.link'>[dcl.link]</a>)
and neither an <i ><a href='dcl.init#nt:initializer'>initializer</a></i> nor a
<i ><a href='dcl.fct.def.general#nt:function-body'>function-body</a></i>,</div></li><li id='2.3'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.3'>(2.3)</a></div><div id='2.3.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':declaration,static_member'></a></span>it declares a non-inline static data member in a class
definition (<a href='class.mem'>[class.mem]</a>, <a href='class.static'>[class.static]</a>),</div></li><li id='2.4'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.4'>(2.4)</a></div><div id='2.4.sentence-1' class='sentence'>it declares a static data member outside a class definition
and the variable was defined within the class with the <span class='texttt'><span class='keyword'>constexpr</span></span>
specifier (this usage is deprecated; see <a href='depr.static_constexpr'>[depr.static_constexpr]</a>),</div></li><li id='2.5'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.5'>(2.5)</a></div><div id='2.5.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':declaration,class_name'></a></span>it is introduced by an <i ><a href='dcl.type.elab#nt:elaborated-type-specifier'>elaborated-type-specifier</a></i> (<a href='class.name'>[class.name]</a>),</div></li><li id='2.6'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.6'>(2.6)</a></div><div id='2.6.sentence-1' class='sentence'>it is an
<span class='indexparent'><a class='index' id=':declaration,opaque_enum'></a></span><i ><a href='dcl.enum#nt:opaque-enum-declaration'>opaque-enum-declaration</a></i> (<a href='dcl.enum'>[dcl.enum]</a>),</div></li><li id='2.7'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.7'>(2.7)</a></div><div id='2.7.sentence-1' class='sentence'>it is a
<span class='indexparent'><a class='index' id=':parameter,template'></a></span><span class='indexparent'><a class='index' id=':template_parameter'></a></span><i ><a href='temp.param#nt:template-parameter'>template-parameter</a></i> (<a href='temp.param'>[temp.param]</a>),</div></li><li id='2.8'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.8'>(2.8)</a></div><div id='2.8.sentence-1' class='sentence'>it is a
<span class='indexparent'><a class='index' id=':declaration,parameter'></a></span><span class='indexparent'><a class='index' id=':parameter_declaration'></a></span><i ><a href='dcl.fct#nt:parameter-declaration'>parameter-declaration</a></i> (<a href='dcl.fct'>[dcl.fct]</a>) in a function
<span class='indexparent'><a class='index' id=':declarator'></a></span>declarator that is not the <i ><a href='dcl.decl#nt:declarator'>declarator</a></i> of a
<i ><a href='dcl.fct.def.general#nt:function-definition'>function-definition</a></i>,</div></li><li id='2.9'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.9'>(2.9)</a></div><div id='2.9.sentence-1' class='sentence'>it is a
<span class='indexparent'><a class='index' id=':declaration,typedef'></a></span><a href='dcl.typedef'><span class='texttt'>typedef</span></a> declaration,</div></li><li id='2.10'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.10'>(2.10)</a></div><div id='2.10.sentence-1' class='sentence'>it is
an <i ><a href='dcl.dcl#nt:alias-declaration'>alias-declaration</a></i> (<a href='dcl.typedef'>[dcl.typedef]</a>),</div></li><li id='2.11'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.11'>(2.11)</a></div><div id='2.11.sentence-1' class='sentence'>it is
a
<i ><a href='namespace.udecl#nt:using-declaration'>using-declaration</a></i> (<a href='namespace.udecl'>[namespace.udecl]</a>),</div></li><li id='2.12'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.12'>(2.12)</a></div><div id='2.12.sentence-1' class='sentence'>it is
a <i ><a href='temp.deduct.guide#nt:deduction-guide'>deduction-guide</a></i> (<a href='temp.deduct.guide'>[temp.deduct.guide]</a>),</div></li><li id='2.13'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.13'>(2.13)</a></div><div id='2.13.sentence-1' class='sentence'>it is
a <i ><a href='dcl.dcl#nt:static_assert-declaration'>static_assert-declaration</a></i> (<a href='dcl.dcl'>[dcl.dcl]</a>),</div></li><li id='2.14'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.14'>(2.14)</a></div><div id='2.14.sentence-1' class='sentence'>it is an
<i ><a href='dcl.dcl#nt:attribute-declaration'>attribute-declaration</a></i> (<a href='dcl.dcl'>[dcl.dcl]</a>),</div></li><li id='2.15'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.15'>(2.15)</a></div><div id='2.15.sentence-1' class='sentence'>it is an
<i ><a href='dcl.dcl#nt:empty-declaration'>empty-declaration</a></i> (<a href='dcl.dcl'>[dcl.dcl]</a>),</div></li><li id='2.16'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.16'>(2.16)</a></div><div id='2.16.sentence-1' class='sentence'>it is
a <i ><a href='namespace.udir#nt:using-directive'>using-directive</a></i> (<a href='namespace.udir'>[namespace.udir]</a>),</div></li><li id='2.17'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.17'>(2.17)</a></div><div id='2.17.sentence-1' class='sentence'>it is
an <a href='temp.explicit'>explicit instantiation</a> declaration, or</div></li><li id='2.18'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#2.18'>(2.18)</a></div><div id='2.18.sentence-1' class='sentence'>it is
an <a href='temp.expl.spec'>explicit specialization</a> whose
<i ><a href='dcl.dcl#nt:declaration'>declaration</a></i> is not a definition<a class='hidden_link' href='#2.18.sentence-1'>.</a></div></li></ul></div> <div id='2.sentence-2' class='sentence'>
A declaration is said to be a <a class='hidden_link' href='#def:definition' id='def:definition'><i >definition</i></a> of each entity that it defines<a class='hidden_link' href='#2.sentence-2'>.</a></div> <div id='2.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#2.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <div id='2.sentence-3' class='sentence'>All but one of the following are definitions:
<pre class='codeblock'>
<span class='keyword'>int</span> a;                          <span class='comment'>// defines <span class='tcode_in_codeblock'>a</span></span>
<span class='keyword'>extern</span> <span class='keyword'>const</span> <span class='keyword'>int</span> c <span class='operator'>=</span> <span class='literal'>1</span>;         <span class='comment'>// defines <span class='tcode_in_codeblock'>c</span></span>
<span class='keyword'>int</span> f<span class='parenthesis'>(</span><span class='keyword'>int</span> x<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='keyword'>return</span> x<span class='operator'>+</span>a; <span class='curlybracket'>}</span>    <span class='comment'>// defines <span class='tcode_in_codeblock'>f</span> and defines <span class='tcode_in_codeblock'>x</span></span>
<span class='keyword'>struct</span> S <span class='curlybracket'>{</span> <span class='keyword'>int</span> a; <span class='keyword'>int</span> b; <span class='curlybracket'>}</span>;     <span class='comment'>// defines <span class='tcode_in_codeblock'>S</span>, <span class='tcode_in_codeblock'>S&#x200b;::&#x200b;a</span>, and <span class='tcode_in_codeblock'>S&#x200b;::&#x200b;b</span></span>
<span class='keyword'>struct</span> X <span class='curlybracket'>{</span>                      <span class='comment'>// defines <span class='tcode_in_codeblock'>X</span></span>
  <span class='keyword'>int</span> x;                        <span class='comment'>// defines non-static data member <span class='tcode_in_codeblock'>x</span></span>
  <span class='keyword'>static</span> <span class='keyword'>int</span> y;                 <span class='comment'>// declares static data member <span class='tcode_in_codeblock'>y</span></span>
  X<span class='parenthesis'>(</span><span class='parenthesis'>)</span><span class='operator'>:</span> x<span class='parenthesis'>(</span><span class='literal'>0</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>                 <span class='comment'>// defines a constructor of <span class='tcode_in_codeblock'>X</span></span>
<span class='curlybracket'>}</span>;
<span class='keyword'>int</span> X<span class='operator'>:</span><span class='operator'>:</span>y <span class='operator'>=</span> <span class='literal'>1</span>;                   <span class='comment'>// defines <span class='tcode_in_codeblock'>X&#x200b;::&#x200b;y</span></span>
<span class='keyword'>enum</span> <span class='curlybracket'>{</span> up, down <span class='curlybracket'>}</span>;              <span class='comment'>// defines <span class='tcode_in_codeblock'>up</span> and <span class='tcode_in_codeblock'>down</span></span>
<span class='keyword'>namespace</span> N <span class='curlybracket'>{</span> <span class='keyword'>int</span> d; <span class='curlybracket'>}</span>          <span class='comment'>// defines <span class='tcode_in_codeblock'>N</span> and <span class='tcode_in_codeblock'>N&#x200b;::&#x200b;d</span></span>
<span class='keyword'>namespace</span> N1 <span class='operator'>=</span> N;               <span class='comment'>// defines <span class='tcode_in_codeblock'>N1</span></span>
X anX;                          <span class='comment'>// defines <span class='tcode_in_codeblock'>anX</span></span>

</pre>
whereas these are just declarations:
<pre class='codeblock'>
<span class='keyword'>extern</span> <span class='keyword'>int</span> a;                   <span class='comment'>// declares <span class='tcode_in_codeblock'>a</span></span>
<span class='keyword'>extern</span> <span class='keyword'>const</span> <span class='keyword'>int</span> c;             <span class='comment'>// declares <span class='tcode_in_codeblock'>c</span></span>
<span class='keyword'>int</span> f<span class='parenthesis'>(</span><span class='keyword'>int</span><span class='parenthesis'>)</span>;                     <span class='comment'>// declares <span class='tcode_in_codeblock'>f</span></span>
<span class='keyword'>struct</span> S;                       <span class='comment'>// declares <span class='tcode_in_codeblock'>S</span></span>
<span class='keyword'>typedef</span> <span class='keyword'>int</span> Int;                <span class='comment'>// declares <span class='tcode_in_codeblock'>Int</span></span>
<span class='keyword'>extern</span> X anotherX;              <span class='comment'>// declares <span class='tcode_in_codeblock'>anotherX</span></span>
<span class='keyword'>using</span> N<span class='operator'>:</span><span class='operator'>:</span>d;                     <span class='comment'>// declares <span class='tcode_in_codeblock'>d</span></span>
</pre></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='3'><div class='marginalizedparent'><a class='marginalized' href='#3'>3</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/basic.tex#L215'>#</a></div><div id='3.note-1' class='note'>[<span style='white-space:nowrap'> </span><a class='note_link' href='#3.note-1'><span class='textit'>Note</span></a><div class='noteBody'><span class='textit'>:</span> <div id='3.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':implementation-generated'></a></span>In some circumstances, C++ implementations implicitly define the
default constructor (<a href='class.default.ctor'>[class.default.ctor]</a>),
copy constructor, move constructor (<a href='class.copy.ctor'>[class.copy.ctor]</a>),
copy assignment operator, move assignment operator (<a href='class.copy.assign'>[class.copy.assign]</a>),
or <a href='class.dtor'>destructor</a> member functions<a class='hidden_link' href='#3.sentence-1'>.</a></div> —<span style='white-space:nowrap'> </span><i>end note</i></div><span style='white-space:nowrap'> </span>]</div>  <div id='3.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#3.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <div id='3.sentence-2' class='sentence'>Given
<pre class='codeblock'>
<span class='preprocessordirective'>#include</span> <span class='anglebracket'>&lt;</span>string<span class='anglebracket'>&gt;</span>

<span class='keyword'>struct</span> C <span class='curlybracket'>{</span>
  std<span class='operator'>:</span><span class='operator'>:</span>string s;    <span class='comment'>// <span class='tcode_in_codeblock'>std&#x200b;::&#x200b;string</span> is the standard library class (<a href='strings'>[strings]</a>)</span>
<span class='curlybracket'>}</span>;

<span class='keyword'>int</span> main<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span>
  C a;
  C b <span class='operator'>=</span> a;
  b <span class='operator'>=</span> a;
<span class='curlybracket'>}</span>
</pre>
the implementation will implicitly define functions to make the
definition of <span class='texttt'>C</span> equivalent to
<pre class='codeblock'>
<span class='keyword'>struct</span> C <span class='curlybracket'>{</span>
  std<span class='operator'>:</span><span class='operator'>:</span>string s;
  C<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='operator'>:</span> s<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>
  C<span class='parenthesis'>(</span><span class='keyword'>const</span> C<span class='operator'>&amp;</span> x<span class='parenthesis'>)</span><span class='operator'>:</span> s<span class='parenthesis'>(</span>x<span class='operator'>.</span>s<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>
  C<span class='parenthesis'>(</span>C<span class='operator'>&amp;</span><span class='operator'>&amp;</span> x<span class='parenthesis'>)</span><span class='operator'>:</span> s<span class='parenthesis'>(</span><span class='keyword'>static_cast</span><span class='anglebracket'>&lt;</span>std<span class='operator'>:</span><span class='operator'>:</span>string<span class='operator'>&amp;</span><span class='operator'>&amp;</span><span class='anglebracket'>&gt;</span><span class='parenthesis'>(</span>x<span class='operator'>.</span>s<span class='parenthesis'>)</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>
      <span class='comment'><span class='rlap'><span class='textnormal'><span class='textit'>//</span></span></span><span class='tcode_in_codeblock'>    : s(std&#x200b;::&#x200b;move(x.s)) { }</span></span>
  C<span class='operator'>&amp;</span> <span class='keyword'>operator</span><span class='operator'>=</span><span class='parenthesis'>(</span><span class='keyword'>const</span> C<span class='operator'>&amp;</span> x<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> s <span class='operator'>=</span> x<span class='operator'>.</span>s; <span class='keyword'>return</span> <span class='operator'>*</span><span class='keyword'>this</span>; <span class='curlybracket'>}</span>
  C<span class='operator'>&amp;</span> <span class='keyword'>operator</span><span class='operator'>=</span><span class='parenthesis'>(</span>C<span class='operator'>&amp;</span><span class='operator'>&amp;</span> x<span class='parenthesis'>)</span> <span class='curlybracket'>{</span> s <span class='operator'>=</span> <span class='keyword'>static_cast</span><span class='anglebracket'>&lt;</span>std<span class='operator'>:</span><span class='operator'>:</span>string<span class='operator'>&amp;</span><span class='operator'>&amp;</span><span class='anglebracket'>&gt;</span><span class='parenthesis'>(</span>x<span class='operator'>.</span>s<span class='parenthesis'>)</span>; <span class='keyword'>return</span> <span class='operator'>*</span><span class='keyword'>this</span>; <span class='curlybracket'>}</span>
      <span class='comment'><span class='rlap'><span class='textnormal'><span class='textit'>//</span></span></span><span class='tcode_in_codeblock'>                { s = std&#x200b;::&#x200b;move(x.s); return *this; }</span></span>
  <span class='operator'>~</span>C<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='curlybracket'>{</span> <span class='curlybracket'>}</span>
<span class='curlybracket'>}</span>;
</pre></div> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='4'><div class='marginalizedparent'><a class='marginalized' href='#4'>4</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/basic.tex#L255'>#</a></div><div id='4.note-1' class='note'>[<span style='white-space:nowrap'> </span><a class='note_link' href='#4.note-1'><span class='textit'>Note</span></a><div class='noteBody'><span class='textit'>:</span> <div id='4.sentence-1' class='sentence'>A class name can also be implicitly declared by an
<i ><a href='dcl.type.elab#nt:elaborated-type-specifier'>elaborated-type-specifier</a></i> (<a href='dcl.type.elab'>[dcl.type.elab]</a>)<a class='hidden_link' href='#4.sentence-1'>.</a></div> —<span style='white-space:nowrap'> </span><i>end note</i></div><span style='white-space:nowrap'> </span>]</div> </div><div class='para' id='5'><div class='marginalizedparent'><a class='marginalized' href='#5'>5</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/basic.tex#L261'>#</a></div><div id='5.sentence-1' class='sentence'><span class='indexparent'><a class='index' id=':type,incomplete'></a></span>In the definition of an object,
the type of that object shall not be
an incomplete type (<a href='basic.types'>[basic.types]</a>),
an <a href='class.abstract'>abstract class type</a>, or
a (possibly multi-dimensional) array thereof<a class='hidden_link' href='#5.sentence-1'>.</a></div></div><div class='footnote' id='footnote-20'><div class='footnoteNumberParent'><a class='marginalized' href='#footnote-20'>20)</a></div><div id='footnote-20.sentence-1' class='sentence'>Appearing inside the brace-enclosed
<i ><a href='dcl.dcl#nt:declaration-seq'>declaration-seq</a></i> in a <i ><a href='dcl.link#nt:linkage-specification'>linkage-specification</a></i> does
not affect whether a declaration is a definition<a class='hidden_link' href='#footnote-20.sentence-1'>.</a></div></div></div></body></html>