constexprメンバ変数を使用してconstexprメンバ変数を初期化したいが、コンパイルしなかった。私はクラスから関数を移動したときはOKでした。それはなぜ起こるのですか?クラスメンバーconstexpr関数を使用してメンバーconstexpr変数を初期化する方法はありますか?constexprメンバ関数を使用したconstexprメンバ変数の初期化
Apple LLVMバージョン8.0.0(clang-800.0.38)を使用しています。
ありがとうございました。
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; }
// This is OK.
constexpr static int kConstantX = Add_Ext(1, 2);
// This results in a compile error.
constexpr static int kConstantY = Add_InClass(1, 2);
};
打ち鳴らすエラーメッセージ:
Constexpr variable 'kConstantY' must be initialized by a constant expression
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1626 – Danh