【问题标题】:unexpected compilation error in a function call (C++) [closed]函数调用中的意外编译错误(C++)[关闭]
【发布时间】:2018-06-13 10:32:06
【问题描述】:

我有一个模板函数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",其他包含的标题是iostream stringboost/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。

【问题讨论】:

标签: c++ function codeblocks boost-tokenizer


【解决方案1】:

您应该听听编译器告诉您的内容。通常错误比你想象的要简单:

temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|

一个额外的右括号。编译器错误的意思是“我以为你已经完成了这个命令,你为什么要关闭另一个括号对?”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多