c++ - 为什么调用了不合适的重载函数?

标签 c++ overloading

为什么下面的代码总是打印“type is double”? (我在 StackOverflow 上看到过这段代码)

#include <iostream>


void show_type(...) {
    std::cout << "type is not double\n";
}

void show_type(double value) { 
    std::cout << "type is double\n"; 
}

int main() { 
    int x = 10;
    double y = 10.3;

    show_type(x);
    show_type(10);
    show_type(10.3);
    show_type(y);


    return 0;
}

最佳答案

http://en.cppreference.com/w/cpp/language/overload_resolution说:

A standard conversion sequence is always better than a user-defined conversion sequence or an ellipsis conversion sequence.

关于c++ - 为什么调用了不合适的重载函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33584489/

相关文章:

c++ - 在这种情况下我会使用哪个循环

C++ 跨边界使用 std::vector

c++ - C++ 中的 main() 是否重载?

c++ - 重载函数中的静态变量

c++ - 避免函数重载

c++ - 将指针传递给 "class that inherits from A and B"

c++ - OpenCV 中的自定义实现

c++ - 优化 switch 语句时出现 Visual Studio 2005 C 编译器问题

c++ - 从重载函数中选择常量表达式?

java - 多态性 - 重载/覆盖