这段C++程序怎么报错啊?

来源:百度知道 编辑:UC知道 时间:2024/05/02 19:12:23
#include <iostream.h>
class List{
private:
int i;
int *p;
int e;
int m,n,j,k;
public:
List(int m,int n,int j,int k){
this.m=m;
this.n=n;
this.j=j;
this.k=k;
}
void output(){
cout<<"("<<m<<","<<n<<","<<j<<","<<k<<")";
}

void main(){
List list=new List(5,3,2,1);
list.output();
}

报错:unexpected end of file found

晕,定义类的时候,最后还少个花括号,花括号后记得还要加上分号。
还有,this是指针,要用指向运算符"->",而不是成员运算符"."。
修改如下:

#include <iostream.h>

class List
{
private:
int i;
int *p;
int e;
int m,n,j,k;

public:
List(int m,int n,int j,int k)
{
this->m=m;
this->n=n;
this->j=j;
this->k=k;
}
void output()
{
cout<<"("<<m<<","<<n<<","<<j<<","<<k<<")";
}
};

void main()
{
List *list=new List(5,3,2,1);
list->output();
cout << endl;
}