析构函数有关例子:
#include<iostream>
using namespace std;
class Point
{
public:
Point(int xx,int yy);//构造函数
~Point();//析构函数(目的用于完成对象被删除前的一些清理工作)
//...其它函数原形
private:
int X,int Y;
};
Point::Point(int xx,int yy)//构造函数的实现
{ X=xx; Y=yy; }
Point::~Point()
{
}
}
//File Stack.h
class Stack
{
public:
Stack ( ){top=bottom=new char[100];}
void push(char c)
{ if((top-bottom)<100) *top++=c;}
char pop( ) { if(- - top>=bottom) {return *top;}}
~Stack( ){delete [ ] bottom;}
private:
char *top,*bottom;
};