error C2143: syntax error : missing ';' before '<class-head>'
来源:互联网 发布:苹果mac启动盘u盘制作 编辑:程序博客网 时间:2024/06/07 01:26
问题:
关于error C2143: syntax error : missing ';' before '<class-head>' 这个错误及解决方法。
解释:
这句话的意思就是在类的前面少加了“;”。
错误代码:
#include <iostream>
using namespace std;
#define maxsize 100
typedef int Datetype
class sequenlist
{
private:
DateType data[maxsize];
int len;
public:
void initiate();
int length();
int insert(DateType x, int i);
int delet(int i);
int locate(DateType x);
DateType get(int i);
};
void sequenlist::initiate()
{
len = 0;
}
int sequenlist::length()
{
return len;
}
int sequenlist::insert(DateType x, int i)
{
int j;
if (len >= maxsize) {
cout << "overflow!\n";
return 0;
} else if ((i < 1) || (i > len + 1)) {
cout << "position is not correct!\n";
return 0;
} else {
for (j = len; j >= i; j--)
data[j] = data[j - 1];
len++;
return 1;
}
}
int sequenlist::delet(int i)
{
int j;
if ((i < 1) || (i > len)) {
cout << "position is not corrcet!\n";
return 0;
} else {
for (j = i; j < len; j++)
data[j - 1] = data[j];
len--;
return 1;
}
}
int sequenlist::locate(DateType x)
{
int j = 0;
while ((j < len) && (data[j] != x))
j++;
if (j < len)
return j + 1;
else
return 0;
}
DateType sequenlist::get(int i)
{
if ((i < 1) && (i > len))
cout << "position is not correct!\n";
else
return data[i - 1];
}
int main()
{
return 0;
}
改完后的代码:
#include <iostream>
using namespace std;
#define maxsize 100
typedef int DateType;
class sequenlist
{
private:
DateType data[maxsize];
int len;
public:
void initiate();
int length();
int insert(DateType x, int i);
int delet(int i);
int locate(DateType x);
DateType get(int i);
};
void sequenlist::initiate()
{
len = 0;
}
int sequenlist::length()
{
return len;
}
int sequenlist::insert(DateType x, int i)
{
int j;
if (len >= maxsize) {
cout << "overflow!\n";
return 0;
} else if ((i < 1) || (i > len + 1)) {
cout << "position is not correct!\n";
return 0;
} else {
for (j = len; j >= i; j--)
data[j] = data[j - 1];
len++;
return 1;
}
}
int sequenlist::delet(int i)
{
int j;
if ((i < 1) || (i > len)) {
cout << "position is not corrcet!\n";
return 0;
} else {
for (j = i; j < len; j++)
data[j - 1] = data[j];
len--;
return 1;
}
}
int sequenlist::locate(DateType x)
{
int j = 0;
while ((j < len) && (data[j] !=x) )
j++;
if (j < len)
return j + 1;
else
return 0;
}
DateType sequenlist::get(int i)
{
if ((i < 1) && (i > len))
cout << "position is not correct!\n";
else
return data[i - 1];
}
int main()
{
return 0;
}
后续:
好郁闷,我是看一本书的代码写的,typedef书上竟然没加分号,误导我,郁闷死了。
- error C2143: syntax error : missing ';' before '<class-head>'
- error C2143: syntax error : missing ';' before '<class-head>'
- error C2143: syntax error : missing ';' before '*'问题
- error C2143: syntax error : missing ';' before '*....
- error C2143: syntax error : missing ';' before '*.... 解决...
- error C2143: syntax error : missing ')' before '*'
- error C2143: syntax error : missing ';' before '*'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before '.'
- error C2143: syntax error : missing ';' before '*.... 解决方案
- error C2143: syntax error : missing \';\' before \'type\'
- error C2143: syntax error : missing ';' before 'type'
- error C2143: syntax error : missing ';' before '}'
- error C2143:syntax error :missing ‘;’before ‘}’
- error C2143: syntax error : missing ';' before 'namespace'
- 迷宫之解。
- Java基础复习:Properties类
- HDU 4561 金山居 连续最大积
- 机房收费系统完美设计——事务处理vs三层架构2
- 基于python的c++ 类空实现代码生成器
- error C2143: syntax error : missing ';' before '<class-head>'
- Sicily 1305 Who’s Winner? (SOJ 1305) 【Nim问题】
- 《中国合伙人》里的三个“千万”
- 图解 Git
- 说的挺好的
- JavaScript的引入
- SendMessage 和 PostMessage 的区别
- 10 个免费超棒的编程用等宽字体
- MyEclipse中开发EJB示例