Definitions and ODR
From cppreference.com
Definitions are declarations that fully define the entity introduced by the declaration. Every declaration is a definition, except for the following:
1) Any declaration with an extern storage class specifier or with a language linkage specifier (such as extern "C") without an initializer
extern const int a; // declares, but doesn't define a extern const int b = 1; // defines b
2) Function declaration without a function body
int f(int); // declares, but doesn't define f
3) Parameter declaration in a function declaration that isn't a definition
int f(int x); // declares, but doesn't define f and x int f(int x) { // defines f and x return x+a; }
4) Declaration of a static data member inside a class definition
struct S { // defines S int n; // defines S::n static int i; // declares, but doesn't define S::i }; int S::i; // defines S::i
5) Declaration of a class name (by forward declaration or by the use of the elaborated type specifier in another declaration)
struct S; // declares, but doesn't define S class Y f(class T p); // declares, but doesn't define Y and T (and also f and p)
7) typedef declaration
typedef S S2; // declares, but doesn't define S2 (S may be incomplete)
- (C++11) alias-declaration
using S2 = S; // declares, but doesn't define S2 (S may be incomplete)
- (C++11) Opaque declaration of an enumeration.
enum Color : int; // declares, but doesn't define Color
using N::d; // declares, but doesn't define d
- using-directive (does not define any entities)
- (C++11) static_assert declaration (does not define any entities)
- (C++11) Attribute declaration (does not define any entities)
- Empty declaration (does not define any entities)
Although asm declaration does not define any entities as well, it is a definition.
Where necessary, the compiler may implicitly define the default constructor, copy constructor, move constructor, copy assignment operator, move assignment operator, and the destructor.
If the definition of any object results in an object of incomplete type, the program is ill-formed.
[edit] One Definition Rule
Only one definition of any variable, function, class type, enumeration type, or template is allowed in any one translation unit.
This section is incomplete Reason: ODR-use: rest of 3.2 and templates |