Original Post
Hello!
I have this situation:
class MY_API CLog : public Singleton<CLog>
{
public:
CLog(); // use default log file (log.txt)
CLog(String FileName);
~CLog() { Close(); }
void Message(String Message);
finline void SetForceFlush(const bool v) { m_ForeFlush = v; }
finline bool GetForceFlush() const { return m_ForeFlush; }
// nice operator :)
template<class T> CLog &operator<<(const T& output)
{
Guard(template<class T> CLog &operator<<(const T& output))
m_LogStream << output;
if (m_ForeFlush) m_LogStream.flush();
return *this;
Unguard();
}
private:
std::ofstream m_LogStream;
bool m_LogOpen;
bool m_ForeFlush;
inline void Open(String Filename); // with this function we open our logfile
inline void Close(); // with this function we close our logfile
};
And here the Singleton:
template<typename Type>
class Singleton
{
protected:
Singleton() {}
virtual ~Singleton()
{
if (ms_pGlobalInstance)
{
delete ms_pGlobalInstance;
ms_pGlobalInstance = 0;
}
else
{}
}
private:
static Type* ms_pGlobalInstance;
public:
inline static Type* GetInstance()
{
if (!ms_pGlobalInstance)
{
ms_pGlobalInstance = new Type();
}
return ms_pGlobalInstance;
}
};
template <typename Type>
Type* Singleton<Type>::ms_pGlobalInstance = 0;
So.. now if the app closes then the deconstructor of the singleton is called. And this should call the singleton of the CLog class.
But the Close() function is never called. Where is my mistake?
Thanks, Christian