如何修复'PCH Warning: header stop not at file scope'

How to fix 'PCH Warning: header stop not at file scope'

本文关键字:not at file scope stop Warning 何修复 PCH header      更新时间:2023-10-16

我已经将我的程序和头文件设置为我认为正确的方法,但我不断收到标题中提到的错误。

我尝试搜索此问题的修复程序,其中大多数只是在头文件中的类定义后添加";"。我已经尝试了我能找到的大多数修复程序,结果相同。

以下是标记错误的主程序:

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include "computeGross.h"
#include "computeInsurance.h"
#include "Employee.h" /*<-----------------This is where the error flags*/
using namespace std;
int main()
{ }

这是错误标记的头文件:

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
struct Employee
{
string name;
double rate;
double hours;
double insurance;
double social;
double stateTax;
double fedTax;
double netPay;
double grossPay;
};
#endif

仅供参考,当我在另一个 .h 文件中留下一个 ; 关闭另一个 .h 文件中的声明。由于该声明从未完成,因此当在下一个 .h 文件中遇到 #define 时,它会抛出此错误。

尝试更改头文件的顺序。尝试创建一个新的 cpp 文件,并一次包含一个标头。看看哪一个坏了。

减少错误的可能原因,直到找到它。