jeudi 17 octobre 2019

Is there a way to declare a public static const that will be defined in the source file using constexpr (and what difference is there)?

In my header I have a public static const declared and I define in the source file as a class member. I want to define it in the source file because I am including and using a constant from an it, and I don't want to include in my header.

If I use static constexpr in the header it requires a definition there.

header

public:
  static const double DEG_TO_RADIANS;

source

#include <math.h>

const double MyClass::DEG_TO_RADIANS = (M_PI/180.0);

Is this a situation where you just can't use constexpr, does this matter at all?

Why does a static const allow me to not define the variable but static constexpr doesn't?

Aucun commentaire:

Enregistrer un commentaire