Declaration and Definition
extern to declare a variable.
int i; is a definintion.
extern int i = 10; is also a definintion.
Note that it is an error to provide an initializer on an
extern inside a function. Because variable with
extern is global. extern with initializer in a function is a temperary variable, not a global variable.
#define #ifdef #ifndef #endif to make sure that head file can be included only once.
Name Lookup & Type Checking
In C++, name lookup happens before type checking. So, variable and function cannot have the same name.
We should define
inline functions in headers, and
inline member functions should be defined in the same header as the corresponding class definition.
in-class initializers must use either the
= form of initialization or the direct form of initialization using curly braces.