T
tom
I have a code segment list below, for the function call "calc()" in
the main function, a standard conversion from "double"->"int" is made
while "double"->"LongDouble" is also viable, does anyone know why
standard conversion is picked as the best match by the compilier?
#include <iostream>
class LongDouble
{
public:
operator double() const
{
return 2.0;
}
};
void calc(int a)
{
std::cout<<"void calc(int a) called"<<std::endl;
}
void calc(LongDouble a)
{
std::cout<<"void calc(LongDouble a)"<<std::endl;
}
int main(int argc, char *argv[])
{
double dval = 0.0;
calc(dval);
return 0;
}
the main function, a standard conversion from "double"->"int" is made
while "double"->"LongDouble" is also viable, does anyone know why
standard conversion is picked as the best match by the compilier?
#include <iostream>
class LongDouble
{
public:
operator double() const
{
return 2.0;
}
};
void calc(int a)
{
std::cout<<"void calc(int a) called"<<std::endl;
}
void calc(LongDouble a)
{
std::cout<<"void calc(LongDouble a)"<<std::endl;
}
int main(int argc, char *argv[])
{
double dval = 0.0;
calc(dval);
return 0;
}