Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
„expression“: falsches Argument für „decltype“
Bemerkungen
Der Compiler kann den Typ des Ausdrucks, der das Argument für den decltype(expression) -Typspezifizierer ist, nicht ableiten.
Beispiel
Im folgenden Codebeispiel kann der Compiler den Typ des myFunction -Arguments nicht ableiten, weil myFunction überladen ist. Um dieses Problem zu beheben, können static_cast Sie eine Instanz eines Zeigers auf die bestimmte überladene Funktion erstellen, die im decltype Ausdruck angegeben werden soll.
// C3556.cpp
// compile with: cl /W4 /EHsc C3556.cpp
#include <iostream>
void myFunction(int);
void myFunction(float, float);
void callsMyFunction(decltype(myFunction) fn); // C3556
// One way to fix is to comment out the line above, and
// use static_cast to create specialized function pointer
// instances:
auto myFunctionInt = static_cast<void(*)(int)>(myFunction);
auto myFunctionFloatFloat = static_cast<void(*)(float,float)>(myFunction);
void callsMyFunction(decltype(myFunctionInt) fn, int n);
void callsMyFunction(decltype(myFunctionFloatFloat) fn, float f, float g);
void myFunction(int i) {
std::cout << "called myFunction(" << i << ")" << std::endl;
}
void myFunction(float f, float g) {
std::cout << "called myFunction(" << f << ", " << g << ")" << std::endl;
}
void callsMyFunction(decltype(myFunctionInt) fn, int n) {
fn(n);
}
void callsMyFunction(decltype(myFunctionFloatFloat) fn, float f, float g) {
fn(f, g);
}
int main() {
callsMyFunction(myFunction, 42);
callsMyFunction(myFunction, 0.1f, 2.3f);
}