![]() |
#2
yuyu124092017-03-21 15:21
|

template <typename T>
void swap(T &a, T &b);
int main()
{
int i = 10;
int j = 20;
cout << "i, j = " << i << ", " << j << ".\n";
cout << "using complier generated int swapper:\n";
swap(i, j);
cout << "now i, j = " << i << ", " << j << ".\n";
double x = 24.5;
double y = 81.7;
cout << "x, y = " << x << ", " << y << ".\n";
cout << "using complier generated int swapper:\n";
swap( x, y);
cout << "now x, y = " << x << ", " << y << ".\n";
return 0;
}
template <typename T>
void swap(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
void swap(T &a, T &b);
int main()
{
int i = 10;
int j = 20;
cout << "i, j = " << i << ", " << j << ".\n";
cout << "using complier generated int swapper:\n";
swap(i, j);
cout << "now i, j = " << i << ", " << j << ".\n";
double x = 24.5;
double y = 81.7;
cout << "x, y = " << x << ", " << y << ".\n";
cout << "using complier generated int swapper:\n";
swap( x, y);
cout << "now x, y = " << x << ", " << y << ".\n";
return 0;
}
template <typename T>
void swap(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
只有本站会员才能查看附件,请 登录
在学c++ primer plus里面的例题,但是编译不出来,求大神指教
[此贴子已经被作者于2017-3-21 14:10编辑过]