源程序:
#include <iostream>
using namespace std;
class A
{
private:
int a, b;
public:
A(int k = 4, int j = 0)
{
a = k;
b = j;
}
~A();
void show();
};
void A::show()
{
cout << "a=" << a << "b=" << b << endl;
}
A::~A()
{
cout << "调用析构函数..." << endl;
}
int main()
{
A *p = new A(1);
//A x(1);
//p=&x;
p->show();
p->~A();
system("pause");
return 1;
}
运行结果: