Здравствуйте, Sheridan, Вы писали:
А где в CSingleTone логгер инициализируется в NULL?
S>S>class CLogger
S>{
S>public:
S> CLogger() {m_filename = ".application.log"; start() << "Opening log."; stop();};
S> ~CLogger(){ start() << "Closing log."; stop(); };
S> CLogger &start() { m_mutex.lock(); m_logstream.open(m_filename, std::ofstream::out | std::ofstream::ate | std::ofstream::app); return *this; }
S> void stop() { m_logstream << std::endl; m_logstream.close(); m_mutex.unlock();}
S> template <class T> CLogger &operator<<(const T &value) { m_logstream << value; return *this; }
S>private:
S> std::string m_filename;
S> std::ofstream m_logstream;
S> std::mutex m_mutex;
S>};
S>class CSingleTone
S>{
S>public:
S> CLogger *logger() { if(!m_logger) {m_logger = new CLogger(); } return m_logger; };
S> static CSingleTone *instance();
S>private:
S> CLogger *m_logger;
S>}
S>Someclass
S>{
S> Someclass() { CSingleTone::instance()->logger()->start() << "construct"; CSingleTone::instance()->logger()->stop(); }
S> ~Someclass() { CSingleTone::instance()->logger()->start() << "destruct"; CSingleTone::instance()->logger()->stop(); }
S>}
S>void somewhere()
S>{
S> for(...)
S> {
S> Someclass *sc = new Someclass();
S> ...
S> delete sc;
S> }
S>}
S>