gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:18:17 26 4
gpt4 key购买 nike

为什么下面的代码总是打印“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com