【发布时间】:2020-04-29 00:39:31
【问题描述】:
我正在尝试使用以下测试代码尝试一些基本的重载解析概念:
void foo()
{
void F(int x, int y); // F1
void F(char x, double y); // F2
F('A', 5);
}
我已经“尝试”理解 C++17 标准的适用部分,并且还查看了 cppreference.com。我的理解是,F1 的转换序列由提升和精确匹配组成,而 F2 的转换序列由精确匹配和转换组成。 cppreference.com 部分声明
...
F1 is determined to be a better function than F2 if implicit conversions for all
arguments of F1 are not worse than the implicit conversions for all arguments of
F2, and
1) there is at least one argument of F1 whose implicit conversion is better than
the corresponding implicit conversion for that argument of F2
...
基于以上所有,我认为 F1 应该被接受为最佳候选,因为 F1 的最差转换优于 F2 的最差转换。但是,Microsoft 和 minGW 编译器都会生成“模棱两可”的匹配错误。所以很明显我错过了一些东西。我将不胜感激对我所缺少的内容的解释以及对 C++17 中该信息的引用。谢谢!
【问题讨论】:
标签: c++ overload-resolution ambiguous