JN-PDD

导航

2017年3月24日 #

深拷贝&浅拷贝&引用计数&写时拷贝

摘要: (1).浅拷贝: ***s1、s2、s3共用一块存储空间 ***在浅拷贝中,由于拷贝构造函数和复制运算符重载时,只把已有对象的内容赋给新创建的对象,导致多个对象公用了同一段内存,结果当任意一个对象销毁时他就会释放那段他们公用的内存,当剩下的对象在被销毁时,就回重复的释放那段内存空间,导致程序崩溃 ( 阅读全文

posted @ 2017-03-24 23:49 JN-PDD 阅读(148) 评论(0) 推荐(0) 编辑

动态内存管理

摘要: (1).c中动态内存管理方式 malloc、calloc、realloc在堆上开辟空间、free将申请的空间释放掉 void *malloc( size_t size ); void *calloc( size_t num, size_t size ); void *realloc( void *m 阅读全文

posted @ 2017-03-24 23:46 JN-PDD 阅读(176) 评论(0) 推荐(0) 编辑

inline&friend&操作符重载

摘要: (1).inline:是一种以空间换时间的做法省去调用函数的额外开销,提高程序的运行效率,它对于编译器而言只是一种建议 (2).友元函数:是可以直接访问类的private成员的非成员函数。它是定义在类外的普通函数,它不属于任何类,但需要在类的定义中加以声明 友元类:友元类的所有成员函数都可以是另一个 阅读全文

posted @ 2017-03-24 23:44 JN-PDD 阅读(674) 评论(0) 推荐(0) 编辑

类的六个默认成员函数

摘要: 构造、析构、拷贝构造、赋值运算符重载、取地址操作符重载、const修饰的取地址操作符重载 (1).构造函数:为对象分配空间、进行初始化(初始化列表、构造函数函数体内赋值) class Date { public: Date() { _iYear=2016; _iMonth=1; _iDay=1; } 阅读全文

posted @ 2017-03-24 23:42 JN-PDD 阅读(553) 评论(0) 推荐(0) 编辑

this指针

摘要: class A { public: A(int x1) { x=x1; } void disp() { cout<<"this="<<this<<" when x="<<this->x<<endl; } private: int x; }; int main() { A a(1),b(2),c(3) 阅读全文

posted @ 2017-03-24 23:36 JN-PDD 阅读(155) 评论(0) 推荐(0) 编辑

摘要: eg1: 访问限定符:public、protected、private class Date { public: void SetDate(int iYear=1990,int iMonth=1,int iDay=1) { _iYear=iYear; _iMonth=iMonth; _iDay=iD 阅读全文

posted @ 2017-03-24 23:28 JN-PDD 阅读(114) 评论(0) 推荐(0) 编辑

结构体内存对齐规则

摘要: 1.结构体内存对齐规则 eg1: struct X { char a; int b; double c; }S1; int main() { cout<<sizeof(S1)<<endl; cout<<sizeof(S1.a)<<endl; cout<<sizeof(S1.b)<<endl; cou 阅读全文

posted @ 2017-03-24 22:48 JN-PDD 阅读(260) 评论(0) 推荐(0) 编辑