1. const int AAA = 1; 说明是常量,外部文件可以extern访问 2.static const int AAA = 1; 仅本文件内部可以访问 3. #ifndef M_AAA const int AAA = 1; #endif 根据宏的定义与否,与1的情况完全一样。
致1、2楼: 据在下所知,const 变量是内部链接的,真的可以extern访问吗? 致3楼: const只是个编译时告诉编译器进行严格检查的关键字,运行时没有任何约束力。 [quote=引用 1 楼 davidsu33 的回复:] 1. const int AAA = 1; 说明是常量,外部文件可以extern访问 2.static const int AAA = 1; 仅本文件内部可以访问 3. #ifndef M_AAA const int AAA = 1; #endif 根据宏的定义与否,与1的情况完全一样。
[quote=引用 1 楼 davidsu33 的回复:] 1. const int AAA = 1; 说明是常量,外部文件可以extern访问 2.static const int AAA = 1; 仅本文件内部可以访问 3. #ifndef M_AAA const int AAA = 1; #endif 根据宏的定义与否,与1的情况完全一样。
静态变量 这种方式定义的变量能被本文件内的任何函数使用。其他文件中的函数不可使用。 常量是定以后,在程序运行中不能被改变 #ifndef M_AAA const int AAA = 1; #endif #ifndef M_AAA 用来测试M_AAA有没有被宏定义过,如果没有则对#ifndef和#endif之间的代码进行编译
基础知识吧!可以google下 http://download.csdn.net/detail/max_min_/6333663补补基础!
[quote=引用 11 楼 tom555cat 的回复:] [quote=引用 10 楼 davidsu33 的回复:] [quote=引用 9 楼 tom555cat 的回复:] [quote=引用 1 楼 davidsu33 的回复:] 1. const int AAA = 1; 说明是常量,外部文件可以extern访问 2.static const int AAA = 1; 仅本文件内部可以访问 3. #ifndef M_AAA const int AAA = 1; #endif 根据宏的定义与否,与1的情况完全一样。
[quote=引用 10 楼 davidsu33 的回复:] [quote=引用 9 楼 tom555cat 的回复:] [quote=引用 1 楼 davidsu33 的回复:] 1. const int AAA = 1; 说明是常量,外部文件可以extern访问 2.static const int AAA = 1; 仅本文件内部可以访问 3. #ifndef M_AAA const int AAA = 1; #endif 根据宏的定义与否,与1的情况完全一样。
[quote=引用 9 楼 tom555cat 的回复:] [quote=引用 1 楼 davidsu33 的回复:] 1. const int AAA = 1; 说明是常量,外部文件可以extern访问 2.static const int AAA = 1; 仅本文件内部可以访问 3. #ifndef M_AAA const int AAA = 1; #endif 根据宏的定义与否,与1的情况完全一样。
64,654
社区成员
250,484
社区内容
加载中
试试用AI创作助手写篇文章吧