3
私が持ってる理由にconstexprのと奇怪なエラー
C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type
任意の考えを?
私が持ってる理由にconstexprのと奇怪なエラー
C:\...\Options_Dialog.hpp:129: error: enclosing class of 'bool Options_Dialog::is_concurrency_selected() const' is not a literal type
任意の考えを?
あなたのクラスがリテラルタイプではないことを意味します... 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
の意味を理解していないようです。私はそれについての本を読むことをお勧めします(もしそのような本がすでに存在するなら、とにかく)。
'return ConcurrentGBx-> isChecked()'これもconstexprですか?どのようなOSのコンパイラ? – RedX
なぜ関数の後にconstを追加しますか? 既にconstexprです – TimKouters