8 Feb
2004
8 Feb
'04
12:56 a.m.
On Sat, 07 Feb 2004 23:12:58 -0600, Joshua Little wrote
LoggerMap::iterator i = loggers.find(logger); if (!(*i).second.get()) {
If logger doesn't already exist in loggers, then i will be loggers.end(). Dereferencing end() is undefined. Use this for your conditional instead: if(i != loggers.end()) Or, if you want to gain speed, do this: boost::shared_ptr<Logger> LoggerFactory::getInstance(std::string& logger) { boost::shared_ptr<Logger>& TheLoggerRef = loggers[logger]; if(!TheLoggerRef.get()) TheLoggerRef.reset(new Logger()); return TheLoggerRef; } This version searches the map only once. find() doesn't add entries, but the array operator does. Todd