C++为什么我会得到“不命名类型”错误?

问题描述:

我主要的I类有:C++为什么我会得到“不命名类型”错误?

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

其中main.h文件#包括 “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’ does not name a type

为什么这么说?

谢谢...

编辑,找到它。 main.h没有保存,并且#include“outPut.h”被取消。

+0

你如何编译这个? – 2011-04-28 18:14:26

+0

@Mihran它不是一个链接错误,所以编译可能不需要的信息。 – alternative 2011-04-28 18:16:23

+0

g ++后跟所有相关文件(在这种情况下,g ++ main.cpp outPut.cpp properties.cpp particles.cpp – Yotam 2011-04-28 18:16:28

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

+1

我仍然在学习C++。为什么在main.h中包含outPut.h不够好? – 2011-04-28 18:16:22

+0

It is inc通过main.hluded。 – Yotam 2011-04-28 18:17:00

+0

哦,我错过了。 Bleh,删除答案按钮在哪里... – alternative 2011-04-28 18:17:08

grep for OUTPUT_H在所有源文件中。您可能无意中在包含outPut.h之前的其他头文件中定义了include guard。

+0

[grey OUTPUT_H * outPut.h:#ifndef OUTPUT_H outPut .h:#define OUTPUT_H outPut.h〜:#ifndef OUTPUT_H outPut.h〜:#define OUTPUT_H 不,一切都很好... – Yotam 2011-04-28 18:18:11

+0

那么,出于某种原因#include“main.h”不包括定义outPut。如果您使用的是g ++,则可以使用-E编译以查看预处理器输出。这应该是内容丰富的。 – ssegvic 2011-04-28 18:24:36