Compilerfehler C2131
Ausdruck wurde nicht als Konstante ausgewertet
Ein Ausdruck, der als const
oder deklariert wurde, constexpr
wurde zur Kompilierzeit nicht als Konstante ausgewertet. Der Compiler muss in der Lage sein, den Wert des Ausdrucks an dem Punkt zu bestimmen, an dem er verwendet wird.
Beispiel
Dieses Beispiel zeigt eine Möglichkeit, den Fehler C2131 zu verursachen und zu beheben.
// 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'