#include<iostream>
using namespace std;
class point{
private:
int x,y;
public:
point(int a,int b);
~point();
};
void fun(point x);
int main()
{
cout<<"inside main"<<endl;
point k1(1,2);
fun(k1);
cout<<"outside main"<<endl;
return 0;
}
point::point(int a,int b)
{
cout<<"construct..."<<endl;
x=a;
y=b;
}
point::~point()
{
cout<<"destruct..."<<endl;
}
void fun(point x)
{
cout<<"hanshu"<<endl;
}
运行结果为:
inside main
construct…
hanshu
destruct…
outside main
destruct…
对象k1,在调用fun()函数时,调用完成时自动调用析构函数,完成析构。!