//---------------------------------------------------------------
// LogFile.h
//---------------------------------------------------------------
#include <cstdio>
class CLogFile
{
public:
CLogFile() { }
~CLogFile() { }
void Init();
void Term();
void Print( char* );
private:
FILE* m_File;
};
extern CLogFile g_Log;
//---------------------------------------------------------------
// LogFile.cpp
//---------------------------------------------------------------
#include "LogFile.h"
CLogFile g_Log;
void CLogFile::Init()
{
// init
}
void CLogFile::Term()
{
// terminate
}
void CLogFile::Print( char* )
{
// do stuff
}
//---------------------------------------------------------------
// Main.cpp:
//---------------------------------------------------------------
g_Log.Init();
g_Log.Print( "Hello, world!" );
g_Log.Term();
//---------------------------------------------------------------
// LogFile.h
//---------------------------------------------------------------
#include <cstdio>
class CLogFile
{
CLogFile();
public:
~CLogFile();
void Print( char* );
static CLogFile* GetInstance();
static void DestroyInstance();
private:
static CLogFile* m_Instance;
FILE* m_File;
};
//---------------------------------------------------------------
// LogFile.cpp
//---------------------------------------------------------------
CLogFile* CLogFile::m_Instance = NULL;
CLogFile* CLogFile::GetInstance()
{
if( !m_Instance )
{
m_Instance = new CLogFile();
}
return m_Instance;
}
void CLogFile::DestroyInstance()
{
delete m_Instance;
m_Instance = NULL;
}
void CLogFile::Print( char* )
{
// do stuff
}
//---------------------------------------------------------------
// Main.cpp:
//---------------------------------------------------------------
CLogFile::GetInstance()->Print( "Hello, world!" );
CLogFile::DestroyInstance();
//---------------------------------------------------------------
// LogFile.h
//---------------------------------------------------------------
namespace LogFile
{
void Init();
voit Term();
void Print( char* );
};
//---------------------------------------------------------------
// LogFile.cpp
//---------------------------------------------------------------
#include "LogFile.h"
#include <stdio.h>
namespace LogFile
{
FILE* m_File;
void Init()
{
// init
}
void Term()
{
// terminate
}
void Print( char* )
{
// do stuff
}
}
//---------------------------------------------------------------
// Main.cpp:
//---------------------------------------------------------------
LogFile::Init();
LogFile::Print( "hello, world!" );
LogFile::Term();
class Collision
{
static void PointSphere( Vec3& v, Sphere& s );
static void SphereSphere( Sphere& s1, Sphere& s2 );
}
What's the point in using a class with only static methods? Those functions are just collision routines that share no data and should go into a common namespace IMHO.