I'm working on making a factory class but have run into a problem. I
think I'm trying to get the shared pointer out the wrong way.
std::map LoggerFactory::loggers;
boost::shared_ptr<Logger> LoggerFactory::getInstance(std::string& logger) {
boost::shared_ptr<Logger> TheLogger;
LoggerMap::iterator i = loggers.find(logger);
if (!(*i).second.get()) {
TheLogger.reset(new Logger());
loggers[logger] = TheLogger;
}
else {
TheLogger = (*i).second;
}
return TheLogger;
}
I thought that the TheLogger = (*i).second line was the correct way to
get any logger within the map but when I run it I get this segfault:
Program received signal SIGSEGV, Segmentation fault.
LoggerFactory::getInstance(std::string&) (logger=@0x22ff58)
at e:/boost-1.30.2/boost/detail/shared_count.hpp:123
123 if(use_count_ == 0 && weak_count_ != 0)
boost::throw_exception(boost::bad_weak_ptr());
if I comment out the 'TheLogger = (*i).second;' line everything seems to
fine.
Any ideas?
Joshua.