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

忍禁

关注

阅读 69

2022-06-08

源程序:

#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;

}


精彩评论(0)

0 0 举报