我有一个模板函数makeMatrix()
,代码是:
template<size_t N>
void makeMatrix(string dataFilePath, int adjcMatrix[N][N])
{
fstreamExtension fe("adj.txt", ios::in|ios::binary);
string s;
vector<int> temp;
int i = 0;
while(!fe.eof())
{
getline(fe, s);
temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|
for(int j = 0; j < N; j++)
adjcMatrix[i][j] = temp[j];
i += 1;
}
}
fstreamExtension 是我创建的一个类,通过 header 包含在程序中
#include "fstreamExtension.h"
,其他包含的 header 是iostream
string
和boost/tokenizer.hpp
.
代码tokenizeToInt()
:
vector<int> tokenizeToInt(string& intString, const char* seperators)
{
vector<int> intValues;
boost::char_separator<char> delims(seperators);
boost::tokenizer<boost::char_separator<char>> tokens(intString, delims);
for (const auto& t : tokens) {
intValues.push_back(atoi(t.c_str()));
}
return intValues;
}
为什么它会导致编译错误makeMatrix()
,语法似乎正确,我没有调用它main()
,正在编译一些其他代码,然后当我开始构建时弹出这个错误。
IDE:代码块 16.01,gcc。