这是一个随机的、不完整的插图:
class Foo; // (incomplete forward) class declaration
class Foo { // class definition
int a; // member declaration + definition
int b(int, int); // member function declaration
static int c; // static member declaration
};
int Foo::b(int a, int b) { return a+b; } // member function definition
int Foo::c; // static member defintion
int bar(int); // free function declaration
int main() { // free function declaration + definition
int q; // declaration + definition
q = bar(0);
return q;
}
int bar(int a) { return 2 * a; } // free function definition
也许“静态成员定义”是独一无二的,因为它为在别处声明的对象提供了一个实际的对象实例(即分配加构造)。这只能与纯外部声明相媲美:
extern int N; // declaration only, no definition
不要与具有外部可见性的声明+定义混淆:
extern const int M = 11; // declaration and definition