在C++中,重载函数的优先级采用谁更精确,采用谁的策略
。那普通函数,模板函数,变参函数的优先级是怎样的呢?先放结论:普通函数 > 模板函数 > 变参函数。下面看一个例子:
#include <iostream>
void f(...) {
std::cout << "variadic" << std::endl;
}
void f(const int t) {
std::cout << "normal function" << std::endl;
}
template <typename T>
void f(const T &t) {
std::cout << "template" << std::endl;
}
int main(void) {
f(1); // 输出:normal function
return 0;
}