2012-07-09 55 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等。