C++对象数组

来源:互联网 发布:怎样快速提高淘宝等级 编辑:程序博客网 时间:2024/06/05 02:16
  • 对象数组,其作用就是批量生成多个实例
    其实例化方式,以及访问方法以下图为例:
class Coordinate public: int m iX; int m iY;
               图1
int main(void) Coordinate coord[31; coord[11.m_iX = 10; Coordinate *p = new Coordinate[31; = 26; p->m_iY = 20; delete [Ip; p = NULL; return O;
                                           图2
  • 对象数组实例化,在内存中的实现方式
Coordinate coord[3]; coord[Ol coord[ll coord[21 Coordinate *p = new Coordinate[31; p[ll p[21
【注意】
实例化对象数组时,每一个对象的构造函数都会被执行.
销毁对象数组时,每一个对象的析构函数都会被执行。
来自 <http://www.imooc.com/ceping/8148>
原创粉丝点击