Teilen über


Compilerfehler C2134

'function': Aufruf führt nicht zu einem konstanten Ausdruck

Bemerkungen

Eine als constexpr deklarierte Funktion kann nur andere Als constexpr deklarierte Funktionen aufrufen.

Beispiel

Im folgenden Beispiel wird C2134 generiert:

// C2134.cpp
// compile with: /c
int A() {
    return 42;
}

constexpr int B() {
    return A();  // Error C2134: 'A': call does not result in a constant expression.
}

Mögliche Lösung:

// C2134b.cpp
constexpr int A() {  // add constexpr to A, since it meets the requirements of constexpr.
    return 42;
}

constexpr int B() {
    return A();  // No error
}