[英]Cannot access private member declared in class 'CCustomCommandLineInfo'
我試圖將命令行界面添加到現有的MFC應用程序中,並在此網站上在線找到了一個類。 我已經適應了我的需要,當我嘗試構建時,我收到一條錯誤消息: "error C2248: 'CCustomCommandLineInfo::CCustomCommandLineInfo' : cannot access private member declared in class 'CCustomCommandLineInfo'"
這是我的代碼:
class CCustomCommandLineInfo : public CCommandLineInfo
{
CCustomCommandLineInfo()
{
//m_bExport = m_bOpen = m_bWhatever = FALSE;
m_bNoGUI = m_baMode = FALSE;
}
// for convenience maintain 3 variables to indicate the param passed.
BOOL m_bNoGUI; //for /nogui (No GUI; Command-line)
BOOL m_baMode; //for /adv (Advanced Mode)
// BOOL m_bWhatever; //for /whatever (3rd switch - for later date)
//public methods for checking these.
public:
BOOL NoGUI() { return m_bNoGUI; };
BOOL aModeCmd() { return m_baMode; };
//BOOL IsWhatever() { return m_bWhatever; };
virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast)
{
if(0 == strcmp(pszParam, "/nogui"))
{
m_bNoGUI = TRUE;
}
else if(0 == strcmp(pszParam, "/adv"))
{
m_baMode = TRUE;
}
// else if(0 == strcmp(pszParam, "/whatever"))
// {
// m_bWhatever = TRUE;
// }
}
};
這就是我的InitInstance()中的內容
// parse command line (cmdline.h)
CCustomCommandLineInfo oInfo;
ParseCommandLine(oInfo);
if(oInfo.NoGUI())
{
// Do something
}
else if(oInfo.aModeCmd())
{
// Do whatever
}
我將如何解決這個問題?
你有:
class CCustomCommandLineInfo : public CCommandLineInfo
{
CCustomCommandLineInfo()
{
//m_bExport = m_bOpen = m_bWhatever = FALSE;
m_bNoGUI = m_baMode = FALSE;
}
這使默認構造函數成為private
函數。 這就是為什么您不能使用:
CCustomCommandLineInfo oInfo;
將默認構造函數設為public
。
class CCustomCommandLineInfo : public CCommandLineInfo
{
public:
CCustomCommandLineInfo()
{
//m_bExport = m_bOpen = m_bWhatever = FALSE;
m_bNoGUI = m_baMode = FALSE;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.