const的有关问题
const的问题
在一个源文件中写
在另一个中写
不能运行,为什么在源文件中用const修饰的变量就不能在别的文件中用呢?
------解决方案--------------------
http://bytes.com/topic/c/answers/62013-const-has-internal-linkage-c
------解决方案--------------------
extern const int j;
------解决方案--------------------
很简单,因为int和const int不一样
------解决方案--------------------
在一个源文件中写
- C/C++ code
#include"stdafx.h" #include<stdio.h> void func(void); extern int j; int main(void) { printf("%d\n",j); getche(); return 0; }
在另一个中写
- C/C++ code
extern const int j=7;
不能运行,为什么在源文件中用const修饰的变量就不能在别的文件中用呢?
------解决方案--------------------
http://bytes.com/topic/c/answers/62013-const-has-internal-linkage-c
------解决方案--------------------
extern const int j;
------解决方案--------------------
很简单,因为int和const int不一样
------解决方案--------------------
- C/C++ code
在c++中const有限定变量作用域的作用,它限制变量只在本编译单元内可以使用.