2011-04-28 103 views
0

我主要的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

回答

2

您需要在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

0

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

相關問題