【发布时间】:2014-12-11 09:56:29
【问题描述】:
抱歉,标题不清楚,如果您找到更好的,请随时编辑。一个相关的话题已经在Priority between normal function and Template function进行了深入讨论, 但我没有找到问题的答案。
我的代码是:
template<typename T>
void f(T t){std::cout << "Template 1" << std::endl;} // template 1
template<typename T, typename B>
void f(T t){std::cout << "Template 2" << std::endl;} // template 2
int main () {
f(1); // line 1, template 1 will be called
f<int>(1); // template 1 will be called
f<int,int>(1); // template 2 will be called
}
在第 1 行调用模板 1 函数的可能原因是什么?规范中有明确定义吗?
在第 1 行,我认为编译器应该给出“模棱两可的重载”错误。
【问题讨论】:
标签: c++ templates overloading