#include <iostream>
using namespace std;
class Base
{
public:
virtual void Printf()=0;
};
class Son1 :public Base
{
public:
void Printf()
{
cout << "Son1::Printf()" << endl;
}
};
class Son2 : public Base
{
public:
void Printf()
{
cout << "Son2::Printf()" << endl;
}
};
class Contex
{
public:
void SetContex(Base *b)
{
_b = b;
}
virtual void Printf() = 0;
protected:
Base *_b;
};
class Contex1 : public Contex
{
public:
void Printf()
{
_b->Printf();
}
};
class Contex2 : public Contex
{
public:
void Printf()
{
_b->Printf();
}
};
int main()
{
Contex *ct = new Contex1();
ct->SetContex(new Son1());
ct->Printf();
ct->SetContex(new Son2());
ct->Printf();
return 0;
}