第六版


操作符重载

#include<iostream>
using namespace std; class Time
{
public:
Time()
{
h=m=0;
}
Time(int _h,int _m)
{
h = _h;
m = _m;
}
void show()
{
printf("%02d:%02d \n",h,m);
}
Time operator+(const Time &t)
{
Time result;
result.m = t.m + m;
result.h = t.h + h + result.m/60;
result.m %= 60;
return result;
}
private:
int h;
int m;
}; int main(int argc,char* argv[])
{
Time t(3,45);
Time c(3,15);
Time w = t + c;
w.show(); system("pause");
return 0;
}

const总结

#include<iostream>
using namespace std; class Demo
{
public:
int x;
Demo(int _x):x(_x){} void testConstFunction(int _x) const{ ///错误,在const成员函数中,不能修改任何类成员变量
x=_x; ///错误,const成员函数不能调用非onst成员函数,因为非const成员函数可以会修改成员变量
modify_x(_x);
} void modify_x(int _x){
x=_x;
}
}; int main(int argc,char* argv[])
{
int a = 5;
int b = 10;
const int * p1 = &a; //常数据,不能通过解引用修改数据
int const * p4 = &a; //常数据
int * const p2 = &b; //常指针
const int * const p3 = &a; //常数据和常指针 // p2 = &a; //error
//*p1 = 1; //error
p1 = &b; //ok system("pause");
return 0;
}

存储持续性

自动存储持续性

函数和代码块中的变量

静态存储持续性

函数外定义或static的变量

动态存储持续性

使用new分配的内存一直存在

线程存储持续性

c++11,变量使用thread_local定义时

最新文章

  1. USACO3.1Humble Numbers[...]
  2. php 安装composer
  3. Ubuntu 12.04 禁用触摸板
  4. Working with Other Node Types
  5. Quartz所使用的表的说明
  6. Intellij IDEA 创建消息驱动Bean - 接收JMS消息
  7. 在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache + Mono)转载+补充
  8. unix 环境高级编程-读书笔记与习题解答-第二篇
  9. [Powershell] FTP Download File
  10. Lucene学习总结之七:Lucene搜索过程解析
  11. python对真假的判断方式
  12. SQL随机查询,显示行号,查询数据段
  13. Lucene 4.4 依据Int类型字段删除索引
  14. lock table
  15. Testing a Redux &amp; React web application
  16. TV端:通过遥控器的点击实现图片的上下左右抖动的效果
  17. RHL 6.0学习日记, 先记下来,以后整理。
  18. Hi,腾讯WeTest联合Unity官方打造的性能分析工具UPA,今日全新发布!
  19. struts2简单入门-Action的三种配置方式
  20. Unity打开外部程序exe/Bat文件方案

热门文章

  1. scala开发环境
  2. 白盒测试实践项目(day1)
  3. mysql json格式数据处理
  4. 数据库SQL优化大总结之 百万级数据库优化方案(转)
  5. cef相关
  6. yii2 gridview 新增按钮 动态显示按钮
  7. HDU 4126 Genghis Khan the Conqueror (树形DP+MST)
  8. spark(oom内存溢出异常(out of memory))介绍1
  9. struts2使用验证文件实现校验
  10. Python【变量】