变量定义与声明的区别(4)

时间:2026-01-23

变量定义与声明的区别

同样的,定义(definitions)后再使用同样的声明(declarations)也是错误的:

The distinction between a declaration and a definition may seem pedantic but in fact is quite important.

声明(declarations)和定义(definitions)之间的区别看似有些卖弄学问的嫌疑,但是其实是非常重要的。

Note In C++ a variable must be defined exactly once and must be defined

or declared before it is used.

笔记 在C++里,变量必须被定义一次,最多一次,至少一次,而且必须在使用前

定义(definitions)或者声明(declarations)。

Any variable that is used in more than one file requires declarations that are separate from the variable's definition. In such cases, one file will contain the definition for the variable. Other files that use that same variable will contain declarations for but not a definition of that same variable.

任何一个在多个文件中都要用到的变量都需要在没有其定义(definitions)的文件里对其进行声明(declarations)。在这样的情况下,一般一个文件会包含该变量的定义(definitions)。其他用到该变量的文件就会包含该变量的声明(declarations),而不是定义(definitions)。

*************************THE END*************************

**************************BEGIN**************************

Declaration reforms programs to know the called function,whereas definition let the compiler allocate a certain entity for the function.A function could be declared many times while definition is unique.A definition must contain a function body:{/.../}

*************************THE END*************************

**************************BEGIN**************************

小谈声明(Declaration)和定义(Definition)

-----written by kernelxu(kernelxu@)

变量定义与声明的区别(4).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:4.9 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:19元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219