Boost logo

Boost Users :

From: Joshua Little (ljoshua_at_[hidden])
Date: 2004-02-08 00:12:58


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<std::string, boost::shared_ptr<Logger> > 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net