mercredi 4 novembre 2015

How to define a constexpr variable

I want to use a simple compile time constant for example like this:

double foo(double x) { return x + kConstDouble; }

Now I see at least the following ways to define that constant

namespace { static constexpr double kConstDouble = 5.0; }
namespace { constexpr double kConstDouble = 5.0; }
static constexpr double kConstDouble = 5.0;
constexpr double kConstDouble = 5.0;

Which is the right way to go? Is there a difference when kConstDouble is defined in a header vs a source file?

Aucun commentaire:

Enregistrer un commentaire