关于 const,以下正确的是
2016-07-15 20:17
363 查看
Please choose the right statement about constusage:
添加笔记
收藏
纠错
ABC
对于A和B,int const 和 const int 可以颠倒位置,意义不变
CDE都表示指向const int 的指针,而int *const a 才表示指向int的const指针
正确答案: A B C 你的答案: C E (错误)
const int a; //const integer
int const a; //const integer
int const *a; //a pointer which point to const integer
const int *a; //a const pointer which point to integer
int const *a; // a const pointer which point to integer
添加笔记
收藏
纠错
ABC
对于A和B,int const 和 const int 可以颠倒位置,意义不变
CDE都表示指向const int 的指针,而int *const a 才表示指向int的const指针
class A{ private: const int a = 1; //error: 只有静态整型常量可以在类中初始化 static const int h = 1; //ok static const double h1 = 1.0; //error: 只有静态整型常量才能在类中初始化 const int b,c; int d; int &e=b; //error:只有静态变量才能在类中初始化。但引用必须定义时初始化,怎么办呢?在初始化列表中初始化 int &f; static int g; public: A():c(1),f(d){ //ok:常量,引用只能在构造函数的初始化列表中初始化 b=1;//error:常量只能在构造函数的初始化列表中初始化 d=2;//ok:变量可以在这儿初始化,没问题 g=1;//error:静态变量在构造函数中不能初始化 } };
int A::a; //加上这一句后,上边的g = 1;这一行就没问题了。静态变量必须在类定义体的外部定义一次。 //注意,这儿不能写成static int A::a; static关键字要去掉。
相关文章推荐
- Hibernate 简单使用(三)一对一关联映射
- 【HIHOCODER】The Cats' Feeding Spots
- 如何让多个输入框对齐
- 【AD】取消普通域用户帐号加域权限&授权特定普通域用户加域权限
- android service 学习
- UVA-10815 Andy's First Dictionary
- Android小知识点积累
- unity中的碰撞检测
- eetcode_c++:链表:Swap Nodes in Pairs(024)
- CentOS6.5的用户管理
- VS2013 TeeChart控件使用方法
- cdoj 1334 郭大侠与Rabi-Ribi 贪心+数据结构
- 校外分散实习(8)
- ef第一次启动较慢
- 在windows系统上安装VMware Workstation虚拟机,然后在虚拟机VMware Workstation上安装linux系统,在linux系统安装xshell的服务端,在windows系统上安装xshell。用windows系统上的xshell连接到linux
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
- STL"源码"剖析-重点知识总结
- Ubuntu root用户登录设置
- 浅谈C的scanf
- 【前端开发】CSS布局