///////////////////////////////////////////// // MT3Q7 - Object Factory #include #include template class PrototypeFactory { public: T* Create() { return new T(*_pPrototype); } void Register(T* pPrototype) { _pPrototype = pPrototype; } private: T* _pPrototype; }; class TheObject { public: TheObject(const std::string& str) : _str(str) {} void say() { std::cout << "\n " << _str; } private: std::string _str; }; int main() { std::cout << "\n MT3Q7 - Prototype Factory"; std::cout << "\n ===========================\n"; TheObject to("Hello CSE687"); PrototypeFactory protoFact; protoFact.Register(&to); TheObject* pTO = protoFact.Create(); pTO->say(); delete pTO; std::cout << "\n\n"; }