#include <iostream.h>
class A
{
public:
A(){ cout<<"A::A()"<<endl;}
~A() {cout<<"A::~A()"<<endl;}
};
class B:public A
{
public:
B(){ cout<<"B::B()"<<endl;}
~B() {cout<<"B::~B()"<<endl;}
};
void f(A &x,B y)
{
// x=y;
}
void main()
{
A a;
B b;
f(a,b);
}
运行结果如下:
A::A()
A::A()
B::B()
B::~B()
A::~A()
B::~B()
A::~A()
A::~A()
传值时会调用对象的析构函数