读书人

类的构造函数出错貌似是的,该如何解

发布时间: 2012-02-20 21:18:23 作者: rapoo

类的构造函数出错,貌似是的
#include <iostream>
using namespace std;
#define MAX 100;
class list
{private:
int curr_len;
int curr;
int *data;
public:
list();
list(int );
list(int ,int);
void insert(int ,int);
void dele(int);
int search(int);
void reverse();
int get_first();
~list();
};
list::list()
{data=new int[MAX];//以下同样出错,百思不得其解。以待来者了。这是第26行。
curr_len=0;
curr=0;}
list::list(int a){data=new int [MAX];curr_len=a;curr=0;}
list::list(int a,int b){data=new int [MAX];curr_len=a;curr=0;for(int i=0;i<curr_len;i++)data[i]=b;}
list::~list(){curr_len=0;curr=0;delete[]data;data=NULL;}
报错如下:
zuoye.cpp: In constructor ‘list::list()’:
zuoye.cpp:26: error: expected `]' before ‘;’ token
zuoye.cpp:26: error: expected primary-expression before ‘]’ token
zuoye.cpp:26: error: expected `;' before ‘]’ token
zuoye.cpp: In constructor ‘list::list(int)’:
zuoye.cpp:29: error: expected `]' before ‘;’ token
zuoye.cpp:29: error: expected primary-expression before ‘]’ token
zuoye.cpp:29: error: expected `;' before ‘]’ token
zuoye.cpp: In constructor ‘list::list(int, int)’:
zuoye.cpp:30: error: expected `]' before ‘;’ token
zuoye.cpp:30: error: expected primary-expression before ‘]’ token
zuoye.cpp:30: error: expected `;' before ‘]’ token
g++编译的,VC6也出错


[解决办法]
#define MAX 100;
后面多了一个;

读书人网 >C++

热点推荐