c++ - 错误 : expected primary-expression before ']' token

标签 c++ arrays

我收到错误:

expected primary-expression before ']' token`

在这一行:

berakna_histogram_abs(histogram[], textRad);

有人知道为什么吗?

const int ANTAL_BOKSTAVER = 26;  //A-Z

void berakna_histogram_abs(int histogram[], int antal);

int main() {

   string textRad = "";
   int histogram[ANTAL_BOKSTAVER];

   getline(cin, textRad);

   berakna_histogram_abs(histogram[], textRad);
   return 0;
}

void berakna_histogram_abs(int tal[], string textRad){

   int antal = textRad.length();

   for(int i = 0; i < antal; i++){

      if(textRad.at(i) == 'a' || textRad.at(i) == 'A'){
        tal[0] + 1;
      }
   } 
}

最佳答案

main()中函数调用错误:

berakna_histogram_abs(histogram[], textRad);

应该是:

berakna_histogram_abs(histogram, textRad);

你只需要在函数声明中使用[],而不是在调用函数时。

关于c++ - 错误 : expected primary-expression before ']' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18420334/

相关文章:

c++ - 程序运行时数组总和给出错误答案

c++ - C++中重载赋值运算符的返回类型

javascript - 如何在将 json 对象推送到数组时省略特定键?

c++ - 如何避免忘记在子类中定义 operator== ?

C++ 指针和类层次结构导致段错误难题

c++ - 为什么这个内部类不能编译?

C++指针和数组基础

php - 如何preg_match所有数字而不是url编码的逗号

javascript - 无法让 karma 测试传递给 Controller

java - 将值添加到数组的数组列表的语法