Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ “['标记”之前的gcc错误“应为“')”_C++_Gcc_Compilation - Fatal编程技术网

C++ “['标记”之前的gcc错误“应为“')”

C++ “['标记”之前的gcc错误“应为“')”,c++,gcc,compilation,C++,Gcc,Compilation,我在试图用GCC编译程序时收到了这些错误,我不确定是什么导致了这些错误 functions.h:21: error: expected ')' before '[' token functions.h:22: error: expected ')' before '[' token functions.h:23: error: expected ')' before '[' token functions.h:25: error: expected ')' before '[' token fu

我在试图用GCC编译程序时收到了这些错误,我不确定是什么导致了这些错误

functions.h:21: error: expected ')' before '[' token
functions.h:22: error: expected ')' before '[' token
functions.h:23: error: expected ')' before '[' token
functions.h:25: error: expected ')' before '[' token
functions.h:26: error: expected ')' before '[' token
functions.h:27: error: expected ')' before '[' token
我的程序在visual studio 2012中编译得很好

这是导致错误的头文件

struct subject
{
    char year[5];
    char session;
    char code[8];
    char credit[3];
    char mark[4];
};

struct data
{
    char name[30];
    char id[30];
    char cc[30]; 
    char course[80];
    struct subject subjects[30];
    int gpa;
};

void displayRecord(data [], int);
int nameSearch(data [], char [], int [], int);
void editRecord(data [], int, int);
char getChar(const char [], int);
int getData(data []);
void displayData(data []);
void deleteRecord(data [], int, int);
我是这样调用编译器的:

gcc -o test functions.cpp functions.h main.cpp
我的心理调试能力告诉我你的Visual Studio正在编译C++代码,而GCC编译它为C.,因为你在函数参数中的数据之前缺少了结构关键字。C编译器不知道该怎么做。尝试通过G++来代替GCC和可能性。确保包含源文件的扩展名为.C或.cpp。

问题是您正在将函数.h传递给编译器。这是一个包含文件,您应该让这两个.cpp文件包含它。无需在编译器的命令行调用中传递它。只需从命令行invocati中删除函数.h即可关于海湾合作委员会

因为这是C++,你应该使用G++而不是GCC编译。因为你使用了GCC,编译器处理了函数。h是C,代码无效。 所以,我认为你的汇编应该是

g++ -o test functions.cpp main.cpp
问哪一行是第21行会太多吗?这段代码没有显示问题!您能提供一个吗?您如何调用gcc?void displayRecorddata[],int;是命令行中的第21行Remove functions.h!它尝试使用默认语言C编译函数.h。但是,头不是独立编译的,它们是通过包含在其他翻译单元中来编译的。@DavidHeffernan,用gcc编译提供的代码会给出报告的错误。@David Heffernan至少用gcc编译的。@David Heffernan4.4和4.5,我得到与GCC编译的相同错误。.CPP后缀告诉GCC将函数.CPP和Me..cp作为C++源。但是文件函数。h,它在GCC命令行上传递,导致GCC将它当作C源。可以直接编译头文件,但仅用于检查错误。并且应该使用G+R。比GCC编译C++,虽然它只在链接时很重要。