#include <iostream>
#include <stdio.h>
using namespace std;
class A {
public:
A(){ cout << "A constru" << endl; }
~A(){ cout << "A xigou" << endl; }
};
class B: public A {
public:
B() { cout << "B contru" << endl; }
~B() { cout << "B xigou" << endl; }
};
struct SA {
void foo(){ printf("foo "); }
virtual void bar() { printf("bar "); }
SA(){bar();}
};
struct SB: SA {
void foo() { printf("b_foo "); }
void bar() { printf("b_bar "); }
};
int main() {
A *pA = new B();
delete pA;
SA *p = new SB;
p->foo();
p->bar();
return 0;
}
/*
*结果为:
A constru
B contru
A xigou
bar foo b_bar
*/