c++ - constexpr and bizzare error -
i'm having:
constexpr bool is_concurrency_selected()const { return concurrentgbx->ischecked();//gbx groupbox checkbox }
and i'm getting error:
c:\...\options_dialog.hpp:129: error: enclosing class of 'bool options_dialog::is_concurrency_selected() const' not literal type
any thoughts on why?
it means class not literal type... program invalid, because options
not literal class type. checker
literal type.
struct checker { constexpr bool ischecked() { return false; } }; struct options { options(checker *concurrentgbx) :concurrentgbx(concurrentgbx) { } constexpr bool is_concurrency_selected()const { //gbx groupbox checkbox return concurrentgbx->ischecked(); } checker *concurrentgbx; }; int main() { static checker c; constexpr options o(&c); constexpr bool x = o.is_concurrency_selected(); }
clang prints
test.cpp:12:18: error: non-literal type 'options' cannot have constexpr members constexpr bool is_concurrency_selected()const ^ test.cpp:7:8: note: 'options' not literal because not aggregate , has no constexpr constructors other copy or move constructors struct options {
if fix , make options
constructor constexpr
, example snippet compiles. similar things may apply code.
you appear not understand constexpr
means. recommend reading book (if such book exists already, anyway).
Comments
Post a Comment