首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

const的有关问题

2012-06-06 
const的问题在一个源文件中写C/C++ code#includestdafx.h#includestdio.hvoid func(void)extern int

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有限定变量作用域的作用,它限制变量只在本编译单元内可以使用. 

热点排行