作者supercygnus (......)
看板Programming
標題Re: [問題] 兩題C++的問題.樣板與結構
時間Tue Apr 5 11:04:19 2011
第一題的程式碼
#include <iostream>
#include <cstdlib>
using namespace std;
template <class T>
void swap1(T& x, T& y)
{
T temp;
temp=x;
x=y;
y=temp;
}
int main(void)
{
int a=5,b=8;
double c=1.25,d=6.64;
swap1(a,b);
swap1(c,d);
cout<<a<<" "<<b<<endl;
cout<<c<<" "<<d<<endl;
system("pause");
return 0;
}
函數名稱竟然不能用swap會有錯誤,是編譯器有內定了? 害我卡了好久
改成swap1竟然就可以了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.167.105.145
推 jtmh:有錯誤,那錯讓訊息是?218.175.150.249 04/05 11:52
→ yauhh:如果有內定,錯誤訊息應該會講ambiguous 61.231.64.117 04/05 12:09