基类之间的关系作为一个框架,通过继承能被子类完整保留。
#include <iostream>
using namespace std;
class B
{
public:
virtual ~B();
B();
virtual void Hello();
};
class A
{
public:
virtual ~A();
virtual B* GetB();
void Check();
protected:
A();
};
class MyB : public B
{
public:
MyB();
~MyB();
void Hello();
};
class MyA : public A
{
public:
MyA();
~MyA();
MyB* GetB();
};
/
A::A() {}
A::~A() {}
B* A::GetB()
{
return new B;
}
void A::Check()
{
B* _b = GetB();
_b->Hello();
}
B::B() {}
B::~B() {};
void B::Hello() { cout<< "B created......" <<endl; }
MyA::MyA() {}
MyA::~MyA() {}
MyB* MyA::GetB()
{
return new MyB;
}
MyB::MyB() { }
MyB::~MyB() {}
void MyB::Hello() { cout<< "MyB created....." <<endl; }
//
int main()
{
MyA mya;
mya.Check();
getchar();
return 1;
}