包括自定义对话框类中的MFC View类会出错 [英] including MFC View class in custom dialog class gives error

查看:81
本文介绍了包括自定义对话框类中的MFC View类会出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在MFC单视图应用程序中创建自定义对话框时,仅仅是为了实验,我试图将我的视图类包含在mydialog类中,这会标记错误。



while i am creating a custom dialog in MFC single view application, just for experimentation i was trying to include my view class in mydialog class, which flags error.

// MyDialog.cpp : implementation file
//

#include "stdafx.h"
#include "MFCOne.h"
#include "MyDialog.h"
#include "afxdialogex.h"

// this is the include statement that caused error ...
#include "MFCOneView.h"

// CMyDialog dialog







错误:



错误C2143:语法错误:在''*''




Error :

error C2143: syntax error : missing '';'' before ''*''

推荐答案

之前缺少'';''您可能有实际的语法错误,标头依赖问题或者其他问题SE。我的头文件的个人规则包括:



- 如果使用预编译头文件,.cpp文件中的第一个#include应为stdafx.h(或等效文件) )。这包括永远不应该在.h文件中。

- 紧跟PCH标题后#include应该是与当前文件对应的标题。这将强制您在.h文件中包含该.h文件所需的任何系统头文件(并将修复包含订购的许多问题)。

- 在此#include之后,添加任何其他正确编译.cpp文件所需的项目文件(按您想要的任何顺序;我通常按字母顺序排列)。

- 按照这些#includes,添加任何系统标题(即该船使用.cpp文件所需的编译器,以任何你想要的顺序再次正确编译。请注意,有一些系统标题有排序问题,特别是stl和min()/ max()宏。



使用这些规则,上面的结果会be:



You might have an actual syntax error, a header dependency problem, or something else. My personal rules for header includes are:

- If precompiled headers are used, the first #include in a .cpp file should be "stdafx.h" (or equiv). This include should never be in a .h file.
- Immediately following the PCH header #include should be the header corresponding to the current file. This will force you to include any system headers in the .h file that are required by that .h file (and will fix many problems with include ordering).
- Following this #include, add any other of your project files needed by the .cpp file to compile correctly (in any order you want; I usually do it alphabetically).
- Following these #includes, add any system headers (ie. that ship with the compiler) that are needed by the .cpp file to compile correctly again, in any order that you want. Note that there are some system headers that have ordering trouble, notably with stl and the min()/max() macros.

Using these rules, the result above would be:

// MyDialog.cpp : implementation file
//

#include "stdafx.h"

#include "MyDialog.h"

#include "MFCOne.h"
#include "MFCOneView.h"

#include "afxdialogex.h"

// CMyDialog dialog





这样做可以解决你的问题,也可以更好地向你展示问题所在......



Doing this should either fix your problem or do a better job showing you where the problem lies...


这篇关于包括自定义对话框类中的MFC View类会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆