Cannot access private member declared in class 'CCustomCommandLineInfo'

189 views Asked by At

I am trying to add a command-line interface to an existing MFC application, and found a class online at this website. I have adapted it to my needs and when I try to build I get an error that reads "error C2248: 'CCustomCommandLineInfo::CCustomCommandLineInfo' : cannot access private member declared in class 'CCustomCommandLineInfo'" here's my code:

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;
    // }
  }
};

And here's what I have in my InitInstance()

// parse command line (cmdline.h)
CCustomCommandLineInfo oInfo;
ParseCommandLine(oInfo);
if(oInfo.NoGUI())
  {
    // Do something
  }
else if(oInfo.aModeCmd())
  {
    // Do whatever
  }

How would I go about fixing this?

1

There are 1 answers

0
R Sahu On BEST ANSWER

You have:

class CCustomCommandLineInfo : public CCommandLineInfo
{
  CCustomCommandLineInfo()
  {
    //m_bExport = m_bOpen = m_bWhatever = FALSE;
    m_bNoGUI = m_baMode = FALSE;
  }

That makes the default constructor a private function. That's why you can't use:

CCustomCommandLineInfo oInfo;

Make the default constructor public.

class CCustomCommandLineInfo : public CCommandLineInfo
{
  public:
  CCustomCommandLineInfo()
  {
    //m_bExport = m_bOpen = m_bWhatever = FALSE;
    m_bNoGUI = m_baMode = FALSE;
  }