#include<iostream>
using namespace std;
template<typename T>
void display(T a)
{
cout<<a<<endl;
}
template<typename T,class S>
void display(T t,S s)
{
cout<<t<<" "<<s<<endl;
}
template<typename T,int size>
void display(T t)
{
for(int i=0;i<size;i++) cout<<t<<endl;
}
void main()
{
display<double>(10.23);
display<int,double>(5,3.3);
display<int,5>(6);
}
报错:
error C2995: ‘display’ : template function has already been defined
error C2977: ‘display’ : too many template arguments
解决:
把重名的函数模板块注释掉
改变display(函数名)