dimanche 30 octobre 2016

Where to put C++ constants? In a separated/shared header (main.h) file?

I use to put constants like:

const QString DATETIME_FORMAT     {"yyyy-MM-dd hh:mm:ss.zzz"};

in a separate file, main.h. Actually I put it on a namespace like:

namespace projectx {
  const QString DATETIME_FORMAT     {"yyyy-MM-dd hh:mm:ss.zzz"};
}

And then, when I want to use DATETIME_FORMAT I have to:

#include "../../main.h"
using namespace projectx;

Depending on where the file using main.h is located the path ../../main.h change. That's a little annoying.

Is this approach standart? What's the alternative?

Aucun commentaire:

Enregistrer un commentaire