constexpr 멤버 함수를 사용하여 constexpr 멤버 변수를 초기화하려고했지만 컴파일하지 않았습니다. 내가 클래스에서 함수를 옮기면 괜찮 았어. 왜 그렇게됩니까? 멤버 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