简体   繁体   English

C++ 错误:预期的主表达式之前

[英]C++ error :expected primary-expression before

I wanna use class for code BubblSort but there's some mistakes that i Don't realized Compiler error's that expected primary expression before我想使用 class 代码 BubblSort 但有一些错误我没有意识到编译器错误之前预期的主要表达式

#include <iostream>
using namespace std; 


class BubbleSort {
    pubwlic:

    void getnumber()    ;
    void processnumber(int a[]);
    void displaynumbers(int a[]);

    private :

    int i=0,a[10],x;

};

void BubbleSort :: getnumber()
{
    for(i=0 ;i>> 11;i++)
cin>>x; 
        a[i]=x;
}
//**************
void BubbleSort ::processnumber(int a[]){
    int i=0,temp=0;
    temp=a[i];
    for(int j=11;j>0;j--)
        for(int i=0;i<j;i++)
        if(a[i]>a[i+1]){
            temp=a[i+1];
            a[i+1]=a[i];
            a[i]=temp;

    }
}

void BubbleSort :: displaynumbers(int a[]){
    for(i=0 ;i>> 10;i++)
    cout<< a[i]<<" ";
}
int main () {
    BubbleSort x;
    x.getnumber();
    x.processnumber(int a[10]);
    x.displaynumbers(int a[10]);


}

look at the line below your class definition ^^ pubwlic is not public看看你的 class 定义下面的行^^ pubwlic is not public

In class BubbleSort you wrote pubwlic: .在 class BubbleSort 你写了pubwlic: I don't really want to rewrite your whole code, but there are a lot of mistakes in your understanding of classes and your understanding of passing an array to a function.我真的不想重写您的整个代码,但是您对类的理解以及对将数组传递给 function 的理解存在很多错误。 I'll just list the mistakes here.我将在这里列出错误。

  • If you want to store the array in the class there is no need to pass it into the function, so this void processnumber(int a[]);如果要将数组存储在 class 中,则无需将其传递到 function 中,因此此void processnumber(int a[]); to this void processnumber();到这个void processnumber();
  • In front of all the a[i] put this-> so you take the array stored in the class itself在所有的a[i]前面放this->所以你把数组存储在 class 本身
  • In for loops remember to initialize the iterator with a keyword int.在 for 循环中,请记住使用关键字 int 初始化迭代器。 Like this for(int i = 0; i < 11; i++) .像这样for(int i = 0; i < 11; i++) Don't put in i >> 11. This isn't comparison, this is bitshifting.不要输入 i >> 11。这不是比较,这是位移。
  • Maybe you should consult this program with your IT teacher.也许你应该咨询你的 IT 老师这个程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM