这个错误是怎么回事?missing ')' before '&'

opposever 2009-04-14 09:13:10

typedef struct SqList

{

ElemType *elem; // 存储空间基址

int length; // 当前长度

int listsize; // 当前分配的存储容量(以sizeof(ElemType)为单位)

}SqList;

int InitList(SqList& L) /*这一行提示错误*/

{ // 操作结果:构造一个空的顺序线性表---------------1

L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));

if(!L.elem)

// exit(OVERFLOW); // 存储分配失败

L.length=0; // 空表长度为0

L.listsize=LIST_INIT_SIZE; // 初始存储容量

return 1;

}


D:\c\maopao.c(31) : error C2143: syntax error : missing ')' before '&'
D:\c\maopao.c(31) : error C2143: syntax error : missing '{' before '&'
D:\c\maopao.c(31) : error C2059: syntax error : '&'
D:\c\maopao.c(31) : error C2059: syntax error : ')'
...全文
1228 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
x396448534 2010-07-08
  • 打赏
  • 举报
回复 1
[Quote=引用 6 楼 goodname 的回复:]
你的源代码如果以.c结尾,则缺省按照编译成c语言的方式,则出你这样的错误。

你改为.cpp结尾就可以了

或者你选中这个.c文件,然后鼠标右键,找到编译成c++代码的选项也可以。
[/Quote]

[Quote=引用 8 楼 arong1234 的回复:]
很显然是C编译的问题,你都用引用了,竟然还用.c做扩展名,C++应该用cpp做扩展名
[/Quote][Quote=引用 9 楼 wxc0077 的回复:]
C是不支持引用的
[/Quote]

高手啊,改成指针是正确的
不过我想知道哪本书上有明确指出这点
goodname 2009-04-15
  • 打赏
  • 举报
回复
是的,改成指针。
opposever 2009-04-15
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wxc0077 的回复:]
C是不支持引用的
[/Quote]
c不支持引用啊!!!我以前一直不知道,有时候编译报错,我就把它改成指针了,
不过我现在看的是严的数据结构 C语言板,它上面也是用引用的!!!
那我要在C下面构造这些函数,是不是都要改成指针?
wxc0077 2009-04-14
  • 打赏
  • 举报
回复
C是不支持引用的
arong1234 2009-04-14
  • 打赏
  • 举报
回复
很显然是C编译的问题,你都用引用了,竟然还用.c做扩展名,C++应该用cpp做扩展名
yangkunhenry 2009-04-14
  • 打赏
  • 举报
回复
exit(OVERFLOW); // 存储分配失败

return OVERFLOW;

是编译器不认识exit

其他的没错了,我的VS2005
goodname 2009-04-14
  • 打赏
  • 举报
回复
你的源代码如果以.c结尾,则缺省按照编译成c语言的方式,则出你这样的错误。

你改为.cpp结尾就可以了

或者你选中这个.c文件,然后鼠标右键,找到编译成c++代码的选项也可以。
opposever 2009-04-14
  • 打赏
  • 举报
回复
头文件:

#include <string.h>
#include <ctype.h>
#include <malloc.h>//malloc
#include <limits.h>//int_max
#include <stdio.h>//EOF
#include <stdlib.h>//atoi
#include <io.h>
#include <math.h> // floor(),ceil(),abs()
#include <process.h> // exit()
#include <iostream.h> // cout,cin


// 函数结果状态代码

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2 因为在math.h中已定义OVERFLOW的值为3,故去掉此行



typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
typedef int Boolean; // Boolean是布尔类型,其值是TRUE或FALSE
typedef int ElemType;
#define LIST_INIT_SIZE 10 // 线性表存储空间的初始分配量
#define LISTINCREMENT 2 // 线性表存储空间的分配增量


typedef struct SqList

{

ElemType *elem; // 存储空间基址

int length; // 当前长度

int listsize; // 当前分配的存储容量(以sizeof(ElemType)为单位)

}SqList;

源文件:

#include "maopao.h"
#include <time.h> //时间获取头文件

/*
************************************
*main函数,加入了记时,以便确定程序运行的时间特性
************************************
*/

int main(int argc, char *argv[])
{
clock_t a,b;
double time;



a=clock();




b=clock();

time=(double)(b-a)/CLOCKS_PER_SEC;
//b-a表示程序运行了多少个时钟单元,常量表示每秒有多少个时钟单元,相除即表示b和a之间有多少秒。

printf("The time was: %f seconds\n", time);
return 0;
}

Status InitList(SqList& L)

{ // 操作结果:构造一个空的顺序线性表---------------1

L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));

if(!L.elem)

exit(OVERFLOW); // 存储分配失败

L.length=0; // 空表长度为0

L.listsize=LIST_INIT_SIZE; // 初始存储容量

return OK;

}
goodname 2009-04-14
  • 打赏
  • 举报
回复
如果有自定义头文件的话

也贴出来看看
opposever 2009-04-14
  • 打赏
  • 举报
回复
用的VC6.0,有什么问题吗?
  • 打赏
  • 举报
回复

#define LIST_INIT_SIZE 10

using namespace std;

typedef char ElemType;
typedef struct SqList_l
{

ElemType *elem; // 存储空间基址

int length; // 当前长度

int listsize; // 当前分配的存储容量(以sizeof(ElemType)为单位)

}SqList;

int InitList(SqList& L) /*这一行提示错误*/

{ // 操作结果:构造一个空的顺序线性表---------------1

L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));

if(!L.elem)

// exit(OVERFLOW); // 存储分配失败

L.length=0; // 空表长度为0

L.listsize=LIST_INIT_SIZE; // 初始存储容量

return 1;

}

void main()
{
int i;
SqList l;
i=InitList(l);

}


没有错误
机智的呆呆 2009-04-14
  • 打赏
  • 举报
回复
楼主用的c编译器吧~~

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧