A declaration (Clause [dcl.dcl]) may introduce one or more names into a translation unit or redeclare names introduced by previous declarations. If so, the declaration specifies the interpretation and attributes of these names. A declaration may also have effects including:
a static assertion (Clause [dcl.dcl]),
controlling template instantiation ([temp.explicit]),
use of attributes (Clause [dcl.dcl]), and
nothing (in the case of an empty-declaration).
A declaration is a definition unless it declares a function without specifying the function's body ([dcl.fct.def]), it contains the extern specifier ([dcl.stc]) or a linkage-specification25 ([dcl.link]) and neither an initializer nor a function-body, it declares a static data member in a class definition ([class.mem], [class.static]), it is a class name declaration ([class.name]), it is an opaque-enum-declaration ([dcl.enum]), it is a template-parameter ([temp.param]), it is a parameter-declaration ([dcl.fct]) in a function declarator that is not the declarator of a function-definition, or it is a typedef declaration ([dcl.typedef]), an alias-declaration ([dcl.typedef]), a using-declaration ([namespace.udecl]), a static_assert-declaration (Clause [dcl.dcl]), an attribute-declaration (Clause [dcl.dcl]), an empty-declaration (Clause [dcl.dcl]), or a using-directive ([namespace.udir]).
[ Example: all but one of the following are definitions:
int a; extern const int c = 1; int f(int x) { return x+a; } struct S { int a; int b; }; struct X { int x; static int y; X(): x(0) { } }; int X::y = 1; enum { up, down }; namespace N { int d; } namespace N1 = N; X anX;
whereas these are just declarations:
extern int a; extern const int c; int f(int); struct S; typedef int Int; extern X anotherX; using N::d;
— end example ]
[ Note: In some circumstances, C++ implementations implicitly define the default constructor ([class.ctor]), copy constructor ([class.copy]), move constructor ([class.copy]), copy assignment operator ([class.copy]), move assignment operator ([class.copy]), or destructor ([class.dtor]) member functions. — end note ] [ Example: given
#include <string> struct C { std::string s; }; int main() { C a; C b = a; b = a; }
the implementation will implicitly define functions to make the definition of C equivalent to
struct C { std::string s; C() : s() { } C(const C& x): s(x.s) { } C(C&& x): s(static_cast<std::string&&>(x.s)) { } C& operator=(const C& x) { s = x.s; return *this; } C& operator=(C&& x) { s = static_cast<std::string&&>(x.s); return *this; } ~C() { } };
— end example ]
A program is ill-formed if the definition of any object gives the object an incomplete type ([basic.types]).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4