#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std;
class A {
public:
A () {cout<<" A\n";}
virtual ~A () {cout<<" ~A\n";}
};
class B : public A {
public:
B () :A() {cout<<" B\n";}
virtual ~B() {cout<<" ~B\n";}
};
int main (int, char *[]) {
A *ap = new B;
delete ap;
A b = *ap;
return 0;
}
输出是:
A
B
~B
~A
为什么 A 的最后一个析构函数被 A b = *ap 调用 为什么不在这里调用 A 的构造函数?
谢谢 !!!