-
-
新手学C++模版上的问题
-
发表于:
2010-5-19 19:34
3014
-
#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.相当郁闷。希望能不耻指教一下
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!