作者在 2014-04-27 14:09:31 发布以下内容
#include <iostream>
using namespace std;
class CPoint
{
public:
int x1;
int y1;
void output();
CPoint();//构造
CPoint(int x2,int y2);//重载
~CPoint();//析构
private:
int x2;;
int y2;
int *pCount;
};
void CPoint::output()
{
if(pCount)
(*pCount)++;
else
{
pCount=new int;
*pCount=1;
}
cout<<"the first point is ("<<x1<<','<<y1<<')'<<endl;
cout<<"the second point is ("<<x2<<','<<y2<<')'<<endl;
}
CPoint::CPoint()
{
pCount=0;
cout<<"the first constructor is calling"<<endl;
}
CPoint::CPoint(int x2,int y2)
{
this->x2=x2;
this->y2=y2;
pCount=0;
cout<<"the second constructor is calling"<<endl;
}
CPoint::~CPoint()
{
if(pCount)
{
cout<<"you call output member function "<<*pCount<<"time"<<endl;
delete pCount;
}
else
cout<<"you have not output called memeber function"<<endl;
cout<<"the deconstructor is calling"<<endl;
}
void output(CPoint pt)
{
cout<<"the first point is ("<<pt.x1<<','<<pt.y1<<')'<<endl;
}
void main()
{
if(1==1)
{
CPoint pt;
cout<<"please input two number"<<endl;
cin>>pt.x1>>pt.y1;
pt.output();
pt.output();
pt.output();
output(pt);
}
CPoint pt(10,10);
pt.output();
}//其实我也不怎么懂