共用方式為


編譯器錯誤 C2131

運算式未評估為常數

在編譯時期宣告為 constconstexpr 未評估為常數的表達式。 編譯程式必須能夠在使用表達式時判斷其值。

範例

此範例示範導致錯誤 C2131 的方法,以及如何修正錯誤。

// c2131.cpp
// compile by using: cl /EHsc /W4 /c c2131.cpp

struct test
{
    static const int array_size; // To fix, init array_size here.
    int size_array[array_size];  // C2131
};

const int test::array_size = 42;
c2131.cpp
c2131.cpp(7): error C2131: expression did not evaluate to a constant
c2131.cpp(7): note: failure was caused by non-constant arguments or reference to a non-constant symbol
c2131.cpp(7): note: see usage of 'array_size'

另請參閱

const
constexpr