权利的声明或权利的定义?
请注意,每个定义都必然是 C++ 中的声明,但反之则不然。也就是说,并非每个声明都是定义。
因此,
int a = 0; // A definition and hence also a declaration
Run Code Online (Sandbox Code Playgroud)
以上既是定义,也是声明。
另一方面,如果你要写:
extern int a; // This is a nondefining declaration
Run Code Online (Sandbox Code Playgroud)
上面的语句extern int a;是一个声明,不是定义(又名非定义声明)
而且,
extern int a = 0; // This is a definition and hence also a declaration even when we have used extern!
Run Code Online (Sandbox Code Playgroud)
请注意,即使我们extern在上面的语句中使用了,初始化程序的存在也0使其成为一个定义,因此也是一个声明。