C++模板函数和非模板函数可以构成函数的重载么?模板参数可以作为函数重载的依据么?
输出结果如下:
http://www.cnblogs.com/liyuan989/p/4138378.html
#include "stdafx.h"
#include <iostream>
int compare(int a)
{
std::cout << "ordinary compare 1 arg" << std::endl;
return 0;
}
template <typename T>
int compare(T lhs, T rhs)
{
std::cout << "template compare 2 arg" << std::endl;
return 0;
}
int compare(int a, int b, int c)
{
std::cout << "ordinary compare 3 arg" << std::endl;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
compare(1);
compare(1, 1);
compare(1, 1, 1);
std::cin.get();
return 0;
}