[basic.def] (original) (raw)

6 Basics [basic]

6.2 Declarations and definitions [basic.def]

A declaration ([basic.pre]) may (re)introduce one or more names and/or entities into a translation unit.

If so, the declaration specifies the interpretation and semantic properties of these names.

A declaration of an entity X is a redeclaration of Xif another declaration of X is reachable from it ([module.reach]); otherwise, it is a first declaration.

Each entity declared by a declaration is also defined by that declaration unless:

A declaration is said to be a definition of each entity that it defines.

[Example 1:

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; }X anX; whereas these are just declarations:extern int a; extern const int c; int f(int); struct S; typedef int Int; namespace N1 = N; extern X anotherX; using N::d;

— _end example_]

[Example 2:

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 tostruct C { std::string s; C() : s() { } C(const C& x): s(x.s) { } C(C&& x): s(static_caststd::string&&\(x.s)) { } C& operator=(const C& x) { s = x.s; return *this; } C& operator=(C&& x) { s = static_caststd::string&&\(x.s); return *this; } ~C() { } };

— _end example_]

In the definition of an object, the type of that object shall not be an incomplete type ([basic.types.general]), an abstract class type ([class.abstract]), or a (possibly multidimensional) array thereof.