[英]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.我将在这里列出错误。
void processnumber(int a[]);
如果要将数组存储在 class 中,则无需将其传递到 function 中,因此此void processnumber(int a[]);
to this void processnumber();
到这个void processnumber();
a[i]
put this->
so you take the array stored in the class itself在所有的a[i]
前面放this->
所以你把数组存储在 class 本身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。这不是比较,这是位移。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.