但是const修饰的成员变量可以在定义时初始化啊,不必通过初始化列表。
那么初始化列表的意义何在呢?
——对不同的构造函数初始化不同的const常量值吗?
那么初始化列表的意义何在呢?
——对不同的构造函数初始化不同的const常量值吗?
2016-09-21
视频代码勘误(两种访问对象成员的方式):
Coordinate *p = new Coordinate[5];
for(int i = 0; i < 5; i++) {
(p + i)->x = i;
(p + i)->y = i;
p[i].printX();
p[i].printY();
}
delete []p;
p = NULL;
Coordinate *p = new Coordinate[5];
for(int i = 0; i < 5; i++) {
(p + i)->x = i;
(p + i)->y = i;
p[i].printX();
p[i].printY();
}
delete []p;
p = NULL;
2016-09-20
正确打开方式;-)
Coordinate coor;
coor.x = 10;
coor.y = 10;
coor.printX();
coor.printY();
Coordinate *p = new Coordinate();
//申请失败
if(NULL == p){
return 0;
}
p->x = 20;
p->y = 30;
p->printX();
p->printY();
(*p).x = 30;
(*p).y = 40;
(*p).printX();
(*p).printY();
//释放内存
delete p;
p = NULL;
Coordinate coor;
coor.x = 10;
coor.y = 10;
coor.printX();
coor.printY();
Coordinate *p = new Coordinate();
//申请失败
if(NULL == p){
return 0;
}
p->x = 20;
p->y = 30;
p->printX();
p->printY();
(*p).x = 30;
(*p).y = 40;
(*p).printX();
(*p).printY();
//释放内存
delete p;
p = NULL;
2016-09-17