我正在尝试向现有的MFC应用程序添加命令行界面,并在线at this website找到了一个类。我根据自己的需要调整了它,当我尝试构建时,我收到一条错误,其中显示"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
}
我将如何解决这个问题?
答案 0 :(得分:1)
你有:
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;
}