A declaration может ввести одно или несколько имен в единицу перевода или повторно объявить имена, введенные предыдущими объявлениями. Если это так, в объявлении указываются интерпретация и атрибуты этих имен. Объявление также может иметь следующие последствия:
управления template instantiation,
вывод аргументов руководящего шаблона для конструкторов ([temp.deduct.guide]),
использование attributesи
ничего (в случае с empty-declaration).
Декларация - это definition если
он объявляет функцию без указания тела функции ([dcl.fct.def]),
он содержит extern спецификатор или linkage-specification26 а, но не содержит initializerни а function-body,
он объявляет не встроенный статический член данных в определении класса ([class.mem], [class.static]),
он объявляет статический член данных вне определения класса, и переменная была определена внутри класса с помощью constexpr спецификатора (такое использование устарело; см. [depr.static_constexpr]),
это class name декларация,
это , opaque-enum-declaration
это , template-parameter
это в деклараторе функции, который не является , parameter-declarationdeclaratorfunction-definition
это typedef декларация,
это using-declaration,
это deduction-guide,
это empty-declaration,
это using-directive,
это explicit instantiation декларация, или
это explicit specialization чья declarationне является определением.
[ Example: Все, кроме одного из следующих определений:
int a; // defines a extern const int c = 1; // defines c int f(int x) { return x+a; } // defines f and defines x struct S { int a; int b; }; // defines S, S::a, and S::b struct X { // defines X int x; // defines non-static data member x static int y; // declares static data member y X(): x(0) { } // defines a constructor of X }; int X::y = 1; // defines X::y enum { up, down }; // defines up and down namespace N { int d; } // defines N and N::d namespace N1 = N; // defines N1 X anX; // defines anX
тогда как это просто объявления:
extern int a; // declares a extern const int c; // declares c int f(int); // declares f struct S; // declares S typedef int Int; // declares Int extern X anotherX; // declares anotherX using N::d; // declares d
— end example ]
[ В некоторых случаях реализации C ++ неявно определяют , , , , , или функции - члены. ] [ Учитывая Note: default constructorcopy constructormove constructorcopy assignment operatormove assignment operator destructor — end note Example:
#include <string>
struct C {
std::string s; // std::string is the standard library class (Clause [strings])
};
int main() {
C a;
C b = a;
b = a;
}
реализация будет неявно определять функции, чтобы сделать определение C эквивалентным
struct C { std::string s; C() : s() { } C(const C& x): s(x.s) { } C(C&& x): s(static_cast<std::string&&>(x.s)) { } // : s(std::move(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; } // { s = std::move(x.s); return *this; } ~C() { } };
— end example ]
[ Note: Имя класса также может быть неявно объявлено с помощью elaborated-type-specifier. ] — end note
Программа плохо сформирована, если определение любого объекта дает объекту значение incomplete type.
Появившись внутри приготовился корпусе declaration-seqв linkage-specificationне влияет на заявление , является ли определение.