国际标准书号.h
int isValid(const char str[]);
int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[]);
错误:
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]
不确定我是否理解该错误,因为我有另一个头文件,其中包含不会产生任何错误的相同类型的参数:
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);
- 这些函数原型(prototype)是我们的教授给我们的。
isRegistered
被定义了三次但是参数数量不同,所以当你在main
中使用 X 参数数量的函数时,它会只使用相应的参数吗具有所述参数的版本?我收到与我的
ISBN.cpp
相对应的第二组错误,其中包括我的ISBN.h
:ISBN.cpp:在函数 int isRegistered(FILE*, const char*, char*, char*, char*) 中: ISBN.cpp:36:89: 错误:int isRegistered(FILE*, const char*, char*, char*, char*) 重新声明为不同类型的符号 ISBN.h:2:5: 错误:先前声明的 int isRegistered
国际标准书号.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
是 <cstdio>
的一部分 header ,在您开始在 header 中使用它之前不包括在内。这就像你必须如何#include <iostream>
使用 std::cout
.您通常应该在每个文件的基础上包含您需要的每个 header ,而不是依赖其他文件为您包含它们。
另一件需要注意的事情是,您通常应该先处理列出的第一个错误,然后再处理其他错误。一个错误可能会导致无意义错误的链式 react ,最终很容易让您偏离轨道。
关于C++ 在 char(头文件)之前期望主表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14550850/