// logger.h:
#include <memory>
#include <string>
#include "dphase.h"
#include "destructor.h"
using namespace std;
class Logger {
typedef auto_ptr<Logger> LoggerPtr;
static LoggerPtr& get_instance();
static void destroy_instance()
{ delete get_instance().release(); }
Logger();
~Logger();
friend class auto_ptr<Logger>;
friend class TDestructor<Logger>;
public:
// singleton interface
static Logger& instance() { return *get_instance(); }
void log(string message);
};
// logger.cxx:
#include <iostream>
#include <string>
#include "dphase.h"
#include "destructor.h"
#include "logger.h"
using namespace std;
Logger::Logger()
{
new TDestructor<Logger>(this, DestructionPhase(1));
cout << "Logger created" << endl;
}
Logger::~Logger()
{
cout << "Logger destroyed" << endl;
}
void Logger::log(string message)
{
cerr << "Logger: " << message << endl;
}