错误:“]"标记之前的预期主表达式 [英] error: expected primary-expression before ']' token

查看:52
本文介绍了错误:“]"标记之前的预期主表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了错误:

'"令牌之前的预期主表达式`

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;
      }
   } 
}

推荐答案

您正在将表传递给函数错误.您应该简单地:

You are passing table to function wrong. You should simply:

berakna_histogram_abs(histogram, textRad);

首先您要声明:

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

但是比您要定义的要多:

But than you're trying to define:

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

这样,您的编译器就认为第二个参数是 int 而不是 string .函数的原型应与声明一致.

That's way your compiler think that second argument is int and not a string. Prototype of function should be consistent with declaration.

这篇关于错误:“]"标记之前的预期主表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆