I am trying to write simple logger class, and I ended up with singleton class design. Example bellow:
DataIO.h:
class DataIO
{
private:
static DataIO instance;
public:
static time_t date;
static std::string path;
static FILE* log;
private:
DataIO()
{
date = time(NULL);
path = "#Output_" + std::to_string(date);
std::string buffer = "mkdir " + path;
system(buffer.c_str());
};
~DataIO();
public:
static DataIO getInstance() const { return instance; };
static void restart();
};
DataIO.cpp:
time_t DataIO::date;
std::string DataIO::path;
FILE* DataIO::log;
DataIO DataIO::instance;
Do I have any guaranty about the order in with static fields will be initialized?? Usually i know i don't have any...
But in this case my DataIO constructor require that those three static fields must be declared before constructor is called. And therefore does it force the order in with static fields are declared??