编译时出现以下错误:
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 时会出现此错误,因为 CWnd(及其所有成员)已明确定义。
发生错误的 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 秒后出现和消失。
任何帮助表示赞赏。