关于书上的一段代码求解

JM1989120 2009-07-28 08:04:10
书上的代码“
全局类
class CGlobal
{
public:
CUsers curUser;
CGlobal();
virtual ~CGlobal();

};
因为StdAfx.h默认包含在很多程序中,所以在StdAfx.h中添加包含该全局类的头文件,在程序中直接访问curUser对象,在访问之前要要添加如下命令引入外部变量
extern CUsers curUser;”

为什么我在StdAfx.h添加头文件不成功?
我的代码
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
extern CUser curUser;
#include "Global.h"
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
rename_namespace("ADOCG") rename("EOF", "EndOfFile") rename("BOF", "BeginOfFile")
using namespace ADOCG;
//#include<adoid.h>
//#include<adoint.h>
//#include"icrsint.h"

#endif // _AFX_NO_AFXCMN_SUPPORT

extern CUsers curUser怎么用??
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
JM1989120 2009-07-28
  • 打赏
  • 举报
回复
解决了 谢谢
雪影 2009-07-28
  • 打赏
  • 举报
回复
extern CUsers curUser;只是申明引用外部的一个变量而已。
而你还没有定义CUsers,当然要失败的了(编译不成功)。
你需要添加CUsers定义的头文件。
另外不需要extern CUsers curUser语句,这个和你的CGlobal类中的curUser成员没有任何关系。

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧