看板 Programming 關於我們 聯絡資訊
請教一個問題 我有如下一段程式碼 要讓函式接收各種型態的Vector 但無法編譯 請問要如何修改 謝謝 #include <iostream> #include <vector> template <typename T> int vecSize(vector<T> a); using namespace std; int main() { vector<int> vec(10,0); cout << vecSize(vec) << endl; return 0; } template <typename T> int vecSize(vector<T> a) { return a.size(); } 錯誤訊息如下 D:\My Dropbox\School\Digital Image Processing\fftDev\main.cpp|3|error: template declaration of 'int vecSize'| D:\My Dropbox\School\Digital Image Processing\fftDev\main.cpp|3|error: 'vector' was not declared in this scope| D:\My Dropbox\School\Digital Image Processing\fftDev\main.cpp|3|error: expected primary-expression before '>' token| D:\My Dropbox\School\Digital Image Processing\fftDev\main.cpp|3|error: 'a' was not declared in this scope| D:\My Dropbox\School\Digital Image Processing\fftDev\main.cpp||In function 'int main()':| D:\My Dropbox\School\Digital Image Processing\fftDev\main.cpp|10|error: 'vecSize' was not declared in this scope| ||=== Build finished: 5 errors, 0 warnings ===| -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.232.184.24
akasan:你的你prototype放在using前面,他認不得vec 61.60.216.177 01/01 02:04
diskk:原來只有一行之差,感謝您!! 125.232.184.24 01/01 02:09
tomap41017:這是線上編譯嗎??140.112.244.171 01/01 21:49
loveme00835:樓上的意思是? >"<140.121.197.115 01/01 21:56
tomap41017:就是compiler在dropbox上嗎?140.112.244.171 01/03 19:25
tomap41017:不然error msg怎麼印出來在那邊XD140.112.244.171 01/03 19:25
LPH66:那個是本機資料夾而已吧 XD 140.112.28.92 01/05 01:46