简体   繁体   English

C ++期望char之前的primary-expression(头文件)

[英]C++ expected primary-expression before char (header file)

ISBN.h ISBN.h

int isValid(const char str[]);
int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[]); 

error: 错误:

ISBN.h:2:18: error: FILE was not declared in this scope
ISBN.h:2:24: error: fp was not declared in this scope
ISBN.h:2:28: error: expected primary-expression before const
ISBN.h:2:46: error: expected primary-expression before char
ISBN.h:2:59: error: expected primary-expression before char
ISBN.h:2:77: error: expected primary-expression before char
ISBN.h:2:89: error: expression list treated as compound expression in initializer [-fpermissive]   

Not sure I understand the error as I have another header file with the same sort of parameters that doesn't yield any errors: 不确定我是否理解错误,因为我有另一个头文件,其中包含相同类型的参数,不会产生任何错误:

ISBNPrefix.h ISBNPrefix.h

FILE* open(const char filename[]);
int isRegistered(FILE* fp, int area);
int minNoDigits(FILE* fp, int area);
int isRegistered(FILE* fp, int area, const char publisher[]);
int close(FILE* fp);
  1. These function prototypes are given to us by our professor. 这些函数原型由我们的教授提供给我们。
  2. isRegistered is defined three times but with a different amount of paramaters, so when you use the function in main with X amount of parameters, will it just use the corresponding version with said parameters? isRegistered定义了三次,但是使用了不同数量的参数,所以当你在main使用带有X量参数的函数时,它是否只使用带有所述参数的相应版本?
  3. I get a second set of errors corresponding to my ISBN.cpp which includes my ISBN.h : 我得到了与我的ISBN.cpp相对应的第二组错误,其中包括我的ISBN.h

    ISBN.cpp: In function int isRegistered(FILE*, const char*, char*, char*, char*): ISBN.cpp:36:89: error: int isRegistered(FILE*, const char*, char*, char*, char*) redeclared as different kind of symbol ISBN.h:2:5: error: previous declaration of int isRegistered ISBN.cpp:在函数int中是isRegistered(FILE *,const char *,char *,char *,char *):ISBN.cpp:36:89:error:int isRegistered(FILE *,const char *,char *,char *,char *)重新声明为不同类型的符号ISBN.h:2:5:错误:以前的int声明是注册的

ISBN.cpp ISBN.cpp

#include "ISBN.h"
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

int isValid(const char str[])
{

}

int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[])
{

} 

FILE is part of the <cstdio> header, which is not included before you start using it in your header. FILE<cstdio>标头的一部分,在您开始在标头中使用它之前,它不会包含在内。 It's just like how you have to #include <iostream> to use std::cout . 就像你必须#include <iostream>来使用std::cout You should generally include every header you need on a per-file basis and not rely on other files to include them for you. 您通常应该在每个文件的基础上包含所需的每个标头,而不是依赖其他文件来包含它们。

Another thing to note is that you should usually deal with the first listed error before others. 另一件需要注意的事情是,您通常应该先处理第一个列出的错误。 One error can cause a chain reaction of nonsensical errors and end up putting you off track very easily. 一个错误可能导致无意义错误的连锁反应,并最终使您非常容易偏离轨道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM