I wanted to initialize the constexpr member variable using the constexpr member function, but it did not compile. This was normal when I moved a function from a class. Why is this happening? Is there a way to use constexpr member functions to initialize constexpr member variables?
I am using Apple LLVM version 8.0.0 (clang-800.0.38).
Thanks for any help.
constexpr static int Add_Ext(int a, int b) { return a + b; }
class Foo
{
public:
constexpr static int Add_InClass(int a, int b) { return a + b; }
constexpr static int kConstantX = Add_Ext(1, 2);
constexpr static int kConstantY = Add_InClass(1, 2);
};
clang error message:
Constexpr variable 'kConstantY' must be initialized by a constant expression
source
share