I am currently trying to have a compile-time constant variable that is template specialized for several types. Currently, I am using constant expressions such as the following generalized example:
template<typename T>
constexpr T GENERAL_CONSTANT = T(0.01);
template<> constexpr float GENERAL_CONSTANT<float> = float(0.02);
template<> constexpr double GENERAL_CONSTANT<double> = double(0.03);
This code however only seems to work on some compilers/linkers. It will compile and work correctly for Clang 9.0.0 for Windows 10, Clang 6.0.0 for Windows 10, Clang 6.0.0 for Ubuntu 18.04, and GCC for Ubuntu 18.04. But has given the similar multiple redefinition errors in several other configurations such as Clang 10.0.0 on Windows 10 or Clang 10.0.0 on Unix, as well as a few others. The errors will often look similar to this:
/usr/bin/ld: <some path to a.cpp> multiple definition of `GENERAL_CONSTANT<double>'; <some path to a.cpp>: first defined here
/usr/bin/ld: <some path to a.cpp> multiple definition of `GENERAL_CONSTANT<float>'; <some path to a.cpp>: first defined here
Where 'a.cpp' is the file that uses the constant, but does not define them. So given that this error is happening inconsistently depending on compiler and machine, I was curious if this is a non-standard approach to this problem, and if that is true, what approach should I take instead?