c++旧教材--p81(构造函数和析构函数)

源程序:

#include <iostream>

using namespace std;

class Point

{

private:

  int x,y;

public:

  Point(int=0,int=0);

~Point(); 

};

Point::Point(int a,int b):x(a),y(b)

{

  cout<<"Initializing"<<a<<","<<b<<endl;

}

Point::~Point()   //定义析构函数

{

  cout<<"Destructor is active"<<endl;

}

void main()

{

  Point *ptr=new Point[2];

  delete []ptr;

}

posted @ 2019-12-11 13:25  bobo哥  阅读(141)  评论(0编辑  收藏  举报