博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动态内存分配的应用:
阅读量:4555 次
发布时间:2019-06-08

本文共 1087 字,大约阅读时间需要 3 分钟。

 

 

 

1 #include 
2 #include
3 using namespace std; 4 class Point{ 5 public: 6 Point(int newX=0,int newY=0){ 7 cout << "calling constructor" << endl; 8 x=newX; 9 y=newY;10 }11 Point(Point &p){12 x=p.x;13 y=p.y;14 }15 ~Point(){16 cout << "calling destructor " << endl;17 }18 void move(int x,int y){19 this->x+=x;20 this->y+=y;21 }22 int getX() {23 return x;24 }25 int getY() {26 return y;27 }28 private:29 int x,y;30 };31 class PointsArray{32 public:33 PointsArray(int size):size(size){34 array=new Point[size]; 35 }36 Point &getElement(int index){37 if(index>=0&&index
>n;56 PointsArray pa(n);57 cout<
<<" "<
<

输出结果:

    calling constructor

    calling destructor

动态内存分配:

new 数据类型(初始化形参列表)

int *point = new int;   //没有初值

int *point =new int(); //初值为0

int *a=new int[n];

转载于:https://www.cnblogs.com/kblin/p/6883206.html

你可能感兴趣的文章
Spring+SpringMVC+JDBC实现登录
查看>>
生与死之间
查看>>
NEFU 109
查看>>
HDU 5435
查看>>
git从已有分支拉新分支开发
查看>>
滚动条隐藏兼容写法
查看>>
SQL2005查询所有表的大小
查看>>
Shell 正则表达式
查看>>
Docker run命令参数整理
查看>>
qt-opencv配置mingw编译器
查看>>
CSS之Medial Queries的另一用法:实现IE hack的方法
查看>>
oo第三单元总结
查看>>
linux-CentOS6.4下安装oracle11g详解
查看>>
实力为王 八年DBA经验谈
查看>>
2-sat 问题 【例题 Flags(2-sat+线段树优化建图)】
查看>>
ext3.2 右击动态添加node的treepanel
查看>>
Database links
查看>>
1035 插入与归并(25 分)
查看>>
STL中排序函数的用法(Qsort,Sort,Stable_sort,Partial_sort,List::sort)
查看>>
如何解决php 生成验证码图片不显示问题
查看>>