自考新教材--p96

源程序:

#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;

}

 运行结果:

posted @ 2019-12-23 08:32  bobo哥  阅读(113)  评论(0编辑  收藏  举报