Delen via


Compilerfout C2131

de expressie evalueerde niet tot een constante

Opmerkingen

Een expressie die is gedeclareerd als const of constexpr werd tijdens het compileren niet geƫvalueerd tot een constante. De compiler moet de waarde van de expressie kunnen bepalen op het punt dat deze wordt gebruikt.

Voorbeeld

In dit voorbeeld ziet u een manier om fout C2131 te veroorzaken en hoe u dit kunt oplossen.

// 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'

Zie ook

Const
constexpr