Error constexpr and bizzare

I have:

constexpr bool is_concurrency_selected()const { return ConcurrentGBx->isChecked();//GBx is a groupbox with checkbox } 

and I get an error:

 C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type 

Any thoughts on why?

+3
source share
1 answer

This means that your class is not a literal type ... This program is not valid because Options not a literal type. But Checker is a literal type.

 struct Checker { constexpr bool isChecked() { return false; } }; struct Options { Options(Checker *ConcurrentGBx) :ConcurrentGBx(ConcurrentGBx) { } constexpr bool is_concurrency_selected()const { //GBx is a groupbox with checkbox return ConcurrentGBx->isChecked(); } Checker *ConcurrentGBx; }; int main() { static Checker c; constexpr Options o(&c); constexpr bool x = o.is_concurrency_selected(); } 

Clang imprints

 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' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors struct Options { 

If you fix this and create an Options constexpr , my code snippet compiles. Similar things may apply to your code.

You don't seem to understand what constexpr means. I recommend reading a book about it (if such a book already exists, anyway).

+6
source

Source: https://habr.com/ru/post/1242853/


All Articles