const的问题
在一个源文件中写
- 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有限定变量作用域的作用,它限制变量只在本编译单元内可以使用.