2012-07-09 56 views
0

我收到以下錯誤(或多個)編譯時:定義的類似乎未定義在編譯時

3>Time Elapsed 00:00:00.10 
2>ClCompile: 
2> Main.cpp 
2> CWnd.cpp 
2>c:\repo\~\clabel.hpp(11): error C2061: syntax error : identifier 'CWnd' 
2>c:\repo\~\cbutton.hpp(11): error C2061: syntax error : identifier 'CWnd' 
2>c:\repo\~\cmainwnd.hpp(9): error C2504: 'CWnd' : base class undefined 
2> CMainWnd.cpp 
2> CLabel.cpp 
2> CException.cpp 
2> CButton.cpp 
2> Generating Code... 
2> 
2>Build FAILED. 

我的項目看起來像這樣(其中每個部分包含頭文件的上一級)

DefaultHeader.hpp : (windows.h, includes CInterface.hpp, other header files) 
-- CInterface.hpp : (includes DefaultHeader.hpp, CWnd.hpp, CLabel.hpp and CButton.hpp) 
-- -- CWnd.hpp : (includes CInterface.hpp) 
-- -- CLabel.hpp : (includes CInterface.hpp) 
-- -- CButton.hpp : (includes CInterface.hpp) 

這裏是CWnd的定義

#ifndef __CWnd_hpp__ 
#define __CWnd_hpp__ 

#pragma once 

#include "CInterface.hpp" 

class CWnd 
{ 
... 
}; 

#endif // __CWnd_hpp__ 

我不確定爲什麼我在嘗試時訪問的CWnd,因爲CWN這個錯誤d(及其所有成員)都有明確的定義。

的3條線發生的錯誤(剪斷出來,以供參考):

CLabel (CWnd* wndParent, INT iX, INT iY, INT iWidth, INT iHeight, LPCTSTR lpszCaption); 

CButton (CWnd* wndParent, INT iX, INT iY, INT iWidth, INT iHeight, LPCTSTR lpszCaption); 

class CMainWnd : public CWnd 

奇怪部分是Itellisense認爲沒有錯誤,直到我編譯,則它們出現,後來消失約2秒。

任何幫助表示讚賞。

+2

'最奇怪的部分是Itellisense在我編譯之前看到沒有錯誤'Intellisense是可能是我依靠發現錯誤的最後一件事。 – Mysticial 2012-07-09 05:17:45

+2

我建議不要使用名稱'CWnd',因爲它是MFC類的名稱。有可能您的某個文件間接包含MFC頭文件? – 2012-07-09 05:25:29

+0

謝謝查爾斯,我會記住這一點。解決它自己雖然:P – kvanberendonck 2012-07-09 05:37:45

回答

0

原來的頭文件CInterface被鎖定,並且在一些文件中沒有包含CWnd.hpp。我通過讓所有文件包含最高級別的包含文件DefaultHeader.hpp來解決此問題,而不是其對應的包含文件CLabel.hpp,CButton.hpp等。