#includeusing namespace std;#define DESTROY_POINTER(ptr) if (ptr) { delete ptr; ptr = NULL; }class Builder{public: virtual ~Builder() {} virtual void Welcome()=0; virtual void City()=0; virtual void End()=0; protected: Builder() {}};class ConcreteBuilderA : public Builder{public: ConcreteBuilderA() {} virtual ~ConcreteBuilderA() {} virtual void Welcome(); virtual void City(); virtual void End();};class ConcreteBuilderB : public Builder{public: ConcreteBuilderB() {} virtual ~ConcreteBuilderB() {} virtual void Welcome(); virtual void City(); virtual void End();};class Director{public: Director(Builder* pBuilder) : m_pBuilder(pBuilder) {} virtual ~Director() { DESTROY_POINTER(m_pBuilder); } void Create(); private: Builder* m_pBuilder;};void ConcreteBuilderA::Welcome(){ cout<<"welcome";}void ConcreteBuilderA::City(){ cout<<" China";}void ConcreteBuilderA::End(){ cout<<"!"< Welcome(); m_pBuilder->City(); m_pBuilder->End();}int main(int argc, char *argv[]){ Director director(new ConcreteBuilderA); director.Create(); return 0;}