简体   繁体   中英

How to access static variable from Dialog header file in MFC

CDialogI have static int mStatus; in CDialogDlg.h . I like to access that static variable from another cpp file , for example test.cpp . Normally is we access static variable as CDialogDlg::mStatus = 1. But when I include CDialogDlg.h into test.h , I got two compilation errors as

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

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

Why I can't include CDialogDlg.h into test.h . I am not very familiar with MFC. Thanks.

As the #include "resource.h" is usually included by default in your header file CMyNameApp.h it should have been #include <afxdialogex.h> . Even though you could have deleted #include "resource.h" from the header, so you would have to include it again.

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

Should solve your whole problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM