#include <iostream>
#include <stack>
using namespace std;
//当函数模板隐式调用时,若同时存在模板函数和非模板函数,优先匹配非模板函数
template<typename T>
inline void foo(T a) {
cout << "in template\t" << a << endl;
}
inline void foo(int a) {
cout << "in specific\t" << a << endl;
}
int main()
{
foo("hello");
foo(9); //优先匹配非模板函数
int ttt = 0;
return 0;
}
本文深入探讨了C++中模板函数与非模板函数的优先级问题,通过实例展示了当两者重名时,编译器如何选择非模板函数进行调用,并解释了这种行为背后的原理。
1304

被折叠的 条评论
为什么被折叠?



