decltype
fails if the function you're calling it on is overloaded, as in this code:
#include <iostream>
int test(double x, double y);
double test(int x, int y);
char test(char x, int y);
int main()
{
std::cout << decltype(test) << std::endl;
return 0;
}
Results:
error: decltype cannot resolve address of overloaded function
I understand that this is because decltype
can't figure out which function you're trying to get the type of. But why isn't there another way to make this work, like this:
std::cout << decltype(test(double, double)) << std::endl;
or this:
double x = 5, y = 2;
std::cout << decltype(test(x, y)) << std::endl;
Since a function cannot be overloaded simply based on return type, wouldn't passing either datatypes or actual variables to the decltype
call be enough to tell it which of the overloads it's supposed to examine? What am I missing here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…