-
-
新手学C++模版上的问题
-
发表于:
2010-5-19 19:34
3013
-
#include <iostream>
template<class any>
void swap(any &a,any &b);
int main()
{
using namespace std;
int i=10;
int j=20;
cout<<"i,j= "<<i<<" ,"<<j<<" .\n";
swap(i,j);
cout<<cout<<"Now i,j= "<<i<<" ,"<<j<<" .\n";
double x=24.5;
double y=81.7;
cout<<"x,y= "<<x<<" ,"<<y<<" .\n";
swap(x,y);
cout<<"now x,y= "<<x<<" ,"<<y<<" .\n"
return 0;
}
template <class any>
void swap(any &a,any &b)
{
any temp;
temp=a;
a=b;
b=temp;
}
在学习模版。定义这样一个模版。编译器竟然报出重载错误。我郁闷。检察很多边了。都看不出那里有问题。
ps.相当郁闷。希望能不耻指教一下
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课