c++ - 函数调用中的意外编译错误 (C++)
问题描述
我有一个模板函数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。
解决方案
你应该听听编译器告诉你什么。通常,错误比您想象的要简单:
temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|
一个额外的右括号。编译器错误的意思是“我以为你已经完成了这个命令,你为什么要关闭另一个括号对?”
推荐阅读
- sql-server - Microsoft SQL Server 中的 Identity(1,1) - 是否有实际理由使用 1,1 以外的值作为种子/增量?
- vb.net - 如何使用 vb.net 文件资源管理器打开多个文档?
- python - Python 中是否有 networkx 和/或 igraph 函数用于查找图的 Alpha 和 Bonacich 功率中心?
- html - 我如何将它组合在一张桌子上?
- java - Java REGEX appendReplacement() 方法不接受第二个参数中的变量
- verilog - Verilog:连接端口的正确方法
- c - 通过 Winsock 将字符串发送到 HDFS
- python - 传递列表后如何修复 append() 错误
- django - 视图没有返回 HttpResponse 对象。它返回 None 而不是
- python-3.x - 使用 Python Boto3 在 Route53 的托管区域中更改记录集权重