While studying C++ I have come across the complex topic of conversion sequences and I have encountered a problem that I couldn't solve on my own.
void g(const double)
{
std::cout << "void g(const double)" << std::endl;
}
void g(const double&&)
{
std::cout << "void g(const double&&)" << std::endl;
}
int main(int argc, char **argv)
{
g(3.14);
return (0);
}
---------------------------- Second example ----------------------------
void g(const double)
{
std::cout << "void g(const double)" << std::endl;
}
void g(const double&)
{
std::cout << "void g(const double&)" << std::endl;
}
int main(int argc, char **argv)
{
g(3.14);
return (0);
}
In this two examples the compiler complains about the fact that the call of the overloaded function "g(double)" is ambiguous.
void g(const double&&)
{
std::cout << "void g(const double&&)" << std::endl;
}
void g(const double&)
{
std::cout << "void g(const double&)" << std::endl;
}
int main(int argc, char **argv)
{
g(3.14);
return (0);
}
But in this example the program compiles properly and prints out "void g(const double&&)". So I don't get why the compiler complains about the first two examples but doesn't about the third.