#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<malloc.h>
class A
{
public:
A()
{
printf("A\n");
}
~A()
{
printf("~A\n");
}
};
class B:public A
{
public:
B()
{
printf("B\n");
}
~B()
{
printf("~B\n");
}
};
class C:public B
{
public:
C(int i)
{
printf("C\n");
}
~C()
{
printf("~C\n");
}
public:
void say()
{
printf("hellworld!\n");
}
};
int main()
{
C c(1);
B b;
A a;
c.say();
return 0;
}
运行结果:
A
B
C
A
B
A
helloworld!
~A
~B
~A
~C
~B
~A