C++11 - Can't define constexpr literal using constexpr function?

前端 未结 2 832
孤街浪徒
孤街浪徒 2021-01-19 23:38

I\'ve run into what seems a counterintuitive error, namely, the inability to assign the value of a constexpr function to a constexpr literal (hope

2条回答
  •  忘掉有多难
    2021-01-20 00:08

    According to the standard, MyClass is considered an incomplete type when you try to invoke FooValue to initialize Foo5. Therefore, you cannot use its members as you did.
    The type is considered a completely-defined object type (or complete type) at the closing }.
    On the other side, the class is regarded as complete within function bodies. That's why Foo5Alt compiles just fine.
    See [class.mem]/6 for further details.

提交回复
热议问题