注册 登录
编程论坛 VC++/MFC

关于CObject的问题,,MFC中的

shendade 发布于 2012-06-07 15:58, 872 次点击
#include "stdafx.h"
#ifndef employ_h
#define employ_h
#include<iostream.h>
//#include<CObject.h>////////这个头文件是什么,下面一句要employ继承它,
class employ:public CObject

还有当我不加#include<CObject.h>时说employ的继承类成员不包含于employ。加上后就只是说不能打开CObject文件了。
请求赐教!!!
2 回复
#2
shendade2012-06-07 21:40
在MFC工程中,当我们新建一个源文件并在里面写函数。当函数里面需要用到我们所创建窗体的类的时候,一般我们只需要include该类的头文件,然后在函数里面声明该窗体类的一个对象即可,然后往往会出现这样的编译错误提示:error C2065: 'IDD_DIALOG1' : undeclared identifier (注:IDD_DIALOG1是我所创建窗体的id号)。出现这个原因是没有定义(废话,呵呵),我们知道资源的定义都是在resources.h文件中,所以解决方法也就容易知道:只要include这个资源头文件即可;另外由于工程主文件的头文件中也是包含这个资源文件的,所以另外一种方法是包含这个工程的头文件即可。

摘自网上的一个解决方法:

Usually this happens in the following scenario: you create a new dialog class, with 2 files, let's say MyDialog.h and MyDialog.cpp. In the .cpp file you have only the following includes:

#include "stdafx.h"
#include "MyDialog.h"

By the time you include MyDialog.h, your IDD_DIALOG1 defined in resource.h is not know. You must include that header. So you have several options:

you include the resource file definition in your MyDialog.h
you include the header for your CWinApp derived class, in your source file, before including MyDialog.h

#include "stdafx.h"
#include "MyWinApp.h" // this file includes resource.h
#include "MyDialog.h"
PS: notice this is a very old thread
#3
shendade2012-06-07 21:42
添加resource.h到对话框的类对象头文件后解决了!!!


// studlg.h : header file
//
#include "stdafx.h"
#include "resource.h" // 很关键的头文件!!!
1