2012-03-07 9 views
3

私が持ってる理由にconstexprのと奇怪なエラー

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

任意の考えを?

+0

'return ConcurrentGBx-> isChecked()'これもconstexprですか?どのようなOSのコンパイラ? – RedX

+0

なぜ関数の後にconstを追加しますか? 既にconstexprです – TimKouters

答えて

6

あなたのクラスがリテラルタイプではないことを意味します... 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の意味を理解していないようです。私はそれについての本を読むことをお勧めします(もしそのような本がすでに存在するなら、とにかく)。