const
2016-05-04 19:00
357 查看
#include <iostream> using namespace std; class Dog { private: int x; const int y; // 在这里不能进行初始化,只有静态的const才能进行初始化。在运行时分配内存,初始化列表进行初始化, static const int z = 200; // 这个是静态的const数据成员,是共有的,这个是可读的不能够进行修改了。这个是编译时常量, public: Dog(int xx = 12, int yy = 13); void print(); }; Dog::Dog(int xx, int yy) : x(xx),y(yy) // x(xx),y(yy) 这个是初始化列表, { } void Dog::print() { cout << x << ", " << y << ", " << z << endl; } int main() { Dog a(6,9); Dog b(66,99); Dog c(666,999); a.print(); return 0; }
相关文章推荐
- SCVMM-01 Create Highly Available Virtual Machines
- java学习笔记-io流浅析与实例
- GDOI2016游记
- Python-OpenCV 处理图像(六)(七)(八):对象识别 图像灰度化处理 图像二值化处理
- Android 笔记 SurfaceView实现涂鸦,轨迹重新绘制
- MVC开发经验总结
- 成就故事
- 陀螺仪偏航角的夹角计算方法
- vim 常用命令
- NSHelper.showAlertTitle的两种用法 swift
- 获取GET参数
- 对象的创建、内存布局、对象的访问定位
- Android 监听软键盘显示隐藏
- jQuery-each()方法:遍历数组、对象、选择集
- BurpSuite的使用总结
- Android亮度调整解析
- <canvas>学习笔记——文字显示控制
- July 博客中的机器学习系列
- Python-OpenCV 处理图像(四)(五):图像直方图和反向投影 图像中边界和轮廓检测
- c++切割那个文件的代码