@@ -46,16 +46,18 @@ class WebSiteFactory {
4646
4747private:
4848 bool initialized;
49+ #if 0
4950 void InitializeInstanceFields() {
5051 if (! initialized) {
5152 flyWeights = std::map<std::string, WebSite*>();
5253 initialized = true;
5354 }
5455 }
56+ #endif
5557
5658public:
5759 WebSiteFactory () {
58- InitializeInstanceFields ();
60+ // InitializeInstanceFields();
5961 }
6062};
6163
@@ -77,15 +79,15 @@ void ConcreteWebSite::setName(std::string name) {
7779
7880WebSite* WebSiteFactory::getWebSiteCategory (std::string key) {
7981 // if (!flyWeights.containsKey(key)) {
80- if (flyWeights.find (key) ! = flyWeights.end ()) {
81- flyWeights.insert (key, new ConcreteWebSite (key));
82+ if (flyWeights.find (key) = = flyWeights.end ()) {
83+ flyWeights.insert (std::pair<std::string, WebSite*>( key, new ConcreteWebSite (key) ));
8284 }
8385
84- return flyWeights-> get (key);
86+ return flyWeights. find (key)-> second ;
8587}
8688
8789int WebSiteFactory::getWebSiteCount () {
88- return flyWeights-> size ();
90+ return flyWeights. size ();
8991}
9092
9193User::User (std::string name) {
@@ -112,6 +114,7 @@ int main(void) {
112114 wb4->use (new User (" Lincoln" ));
113115 WebSite* wb5 = wf->getWebSiteCategory (" Group" );
114116 wb5->use (new User (" Kenny" ));
115- puts (wf->getWebSiteCount ());
117+ // puts(wf->getWebSiteCount());
116118 return 0 ;
117119}
120+
0 commit comments