[問題] C++ Template
請教一個問題
我有如下一段程式碼
要讓函式接收各種型態的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
→
01/01 02:04, , 1F
01/01 02:04, 1F
→
01/01 02:09, , 2F
01/01 02:09, 2F
推
01/01 21:49, , 3F
01/01 21:49, 3F
→
01/01 21:56, , 4F
01/01 21:56, 4F
推
01/03 19:25, , 5F
01/03 19:25, 5F
→
01/03 19:25, , 6F
01/03 19:25, 6F
推
01/05 01:46, , 7F
01/05 01:46, 7F
Programming 近期熱門文章
PTT數位生活區 即時熱門文章