c++ 为什么我会收到"does not name a type"错误?

c++ Why do I get "does not name a type" error?

本文关键字:name type 错误 not does c++ 为什么      更新时间:2023-10-16

在我的主类中,我有:

#include "main.h"
outPut O;
int main(){
...
}

其中main.h文件包含#include "outPut.h"

"outPut.h"行有:

#ifndef OUTPUT_H
#define OUTPUT_H
#include <iostream>
#include <fstream>
    #include "properties.h"
    #include "particles.h"
    class outPut{
     public:
      outPut();
      std::ofstream file;
      void show(lipid * l);
    };
    #endif

和outPut.cpp:

#include "outPut.h"
outPut::outPut(){
}

当我编译这个时,我得到了错误:

main.cpp:3: error: ' outPut '不存在命名一个类型

为什么?

谢谢…编辑,找到了。main.h未保存,#include "outPut.h"被取消

您需要在main.cpp中添加#include "outPut.h"

为所有源文件中的OUTPUT_H设置grep。您可能无意中在outPut.h之前包含的其他标头中定义了include保护。