翻了好几篇关于deFinition与declaration和博客,都写的很坑人 ,看来我得写1篇了,避免很多新手1入门就被坑了。
deFinition是通过declaration完全的定义了实体,每一个declaration都是deFinition,除下面几种情况。
1,存储类标识符extern开头的或语言连接标识符开头,但未初始化的。
extern "C" void f1(void(*pf)()); // declares a function f1 with C linkage,
int f(int); // declares,but doesnt define f
3.函数中未定义的参数
4.类中声明的静态变量
struct S { // defines S int n; // defines S::n static int i; // declares,but doesnt define S::i }; int S::i; // defines S::i
5.只申明了类的名字,主要用在forward declaration和elaborated type中
struct S; // declares,but doesnt define S class Y f(class T p); // declares,but doesnt define Y and T (and also f and p)
6.模板参数
template<typename T> // declares,but doesnt define T
7.预先申明的模板
template<> struct A<int>; // declares,but doesnt define A
8.typedef声明
typedef S S2; // declares,but doesnt define S2 (S may be incomplete)
9.alias申明