Optionsクラスがリテラル型ではないことを意味します...はリテラル クラス型ではないため、このプログラムは無効です。しかしChecker、リテラル型です。
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();
}
クランプリント
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 {
これを修正してOptionsコンストラクターを作成するとconstexpr、私の例のスニペットがコンパイルされます。同様のことがコードにも当てはまる場合があります。
あなたは意味を理解していないようconstexprです。それについての本を読むことをお勧めします (そのような本がすでに存在する場合)。