C++ const
来源:互联网 发布:怎样安装photoshop软件 编辑:程序博客网 时间:2024/04/29 13:49
1. 在C++中const对象默认为文件的局部变量(作用域是文件局部变量),通过指定const变量为extern,就可以在整个程序中访问const变量
未添加extern,以下程序链接出错
//var.cppconst int MAX = 100;
//var.hextern int MAX;
#include <iostream>using namespace std;#include "var.h"int main(){ int x = MAX; cout << "x = " << x << endl; return 0;}
error:
g++ -o main main.cpp var.cpp
/tmp/cc2YqVv9.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `MAX'
collect2: ld returned 1 exit status
make: *** [main] Error 1
添加extern,以下程序编译OK
//var.cppextern const int MAX = 100;
//var.hextern int MAX;
#include <iostream>using namespace std;#include "var.h"int main(){ int x = MAX; cout << "x = " << x << endl; return 0;}
0 0
- const c
- const【C++】
- const ||c
- C++Const
- [c++]const
- C++:const
- const用法(C/C++)
- C++/C const问题
- 【c/c++】const引用
- readonly vs. const [C#]
- C++(二)const
- C语言const介绍
- C语言const介绍
- readonly vs. const [C#]
- readonly vs. const [C#]
- c++:const 操作小结
- readonly vs. const [C#]
- C中的CONST
- JsonMappingException: failed to lazily initialize及could not initialize异常
- js学习事件-----js模仿手机下拉刷新(1)
- Genesis-3D学习手册——21.地形植被
- Linux安装mysql——源码安装
- Tsung安装使用说明
- C++ const
- SSL和SSH有什么区别
- Genesis-3D学习手册——22.高度图
- poj 1050 To the Max
- linux md5运用。。。
- 解决PHP脚本 MySQL has gone away错误
- R中利用apply、tapply、lapply、sapply、mapply、table等函数进行分组统计
- Genesis-3D学习手册——23.关于地形的其他设置
- 我的IT博客