C++ 在 char(头文件)之前期望主表达式

标签 c++

国际标准书号.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);
  1. 这些函数原型(prototype)是我们的教授给我们的。
  2. isRegistered 被定义了三次但是参数数量不同,所以当你在 main 中使用 X 参数数量的函数时,它会只使用相应的参数吗具有所述参数的版本?
  3. 我收到与我的 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/

相关文章:

c++ - 将版本作为字符串进行比较

c++ - Clang 的 "did you mean ...?"变量名修正算法是如何工作的?

c++ - 如何在 Makefile 中正确包含 -Wl,-rpath,$ORIGIN 链接器参数?

c++ - 重载方法还是使用默认值? C++

C++更改子类中拥有的对象类型

c++ - 无法使用Dev-C++编译简单的SDL程序

C++ ifstream 失败位和坏位

C++ 在运行时更改 HWND 窗口过程

c++ - dynamic_cast 与 base 中的虚拟 AsDerived 方法

c++ - 折叠表达式 vs 编译递归