Megjegyzés
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhat bejelentkezni vagy módosítani a címtárat.
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhatja módosítani a címtárat.
"kifejezés": helytelen argumentum a "decltype" kifejezéshez
Megjegyzések
A fordító nem tudja levezetni annak a kifejezésnek a típusát, amely a decltype( argumentuma).
Example
A következő kód példában a fordító nem tudja levezetni az myFunction argumentum típusát, mert myFunction túlterhelt. A probléma static_cast megoldásához létrehozhat egy mutatópéldányt az adott túlterhelt függvényhez, amelyet a decltype kifejezésben meg szeretne adni.
// 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);
}