gpt4 book ai didi

c++ - 如何从MFC中的Dialog头文件访问静态变量

转载 作者:行者123 更新时间:2023-11-30 02:50:09 24 4
gpt4 key购买 nike

CDialogI 在 CDialogDlg.h 中有 static int mStatus;。我喜欢从另一个 cpp 文件 访问该静态变量,例如 test.cpp。通常我们访问静态变量作为 CDialogDlg::mStatus = 1. 但是当我将 CDialogDlg.h 包含到 test.h 中时,我得到了两个编译错误为

 Error 1: error C2504: 'CDialogEx' : base class undefined

Error 2: error C2065: 'IDD_CDialog_DIALOG' : undeclared identifier

为什么我不能将 CDialogDlg.h 包含到 test.h 中。我对MFC不是很熟悉。谢谢。

最佳答案

作为 #include "resource.h"通常默认包含在头文件中 CMyNameApp.h应该是#include <afxdialogex.h> .即使您可以删除 #include "resource.h"来自 header ,因此您必须再次包含它。

#include "resource.h"
#include <afxdialogex.h>

应该可以解决您的整个问题。

关于c++ - 如何从MFC中的Dialog头文件访问静态变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20651931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com