Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with enum

Problem with enum

Scheduled Pinned Locked Moved C / C++ / MFC
help
17 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    bdiamond wrote: I know it's something very stupid... No, just something you may not have thought of. The enum keyword is not like typedef in that you also have to declare an actual variable of the new type before it can be used. So, just remove the _MODE MODE; statement, and change the three references to MODE to be _MODE instead. Make sense?


    "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

    B Offline
    B Offline
    BlackDice
    wrote on last edited by
    #3

    I tried that first with just 'MODE' as the name of the enum like this:

    class CBugReporterApp : public CWinApp
    {
    public:
    	CBugReporterApp();
    	enum MODE {NEWMODE,EDITMODE,BROWSEMODE} ;
    
    	
    
    
    // Overrides
    public:
    	virtual BOOL InitInstance();
    
    // Implementation
    	afx_msg void OnAppAbout();
    	DECLARE_MESSAGE_MAP()
    	void SetAppState(MODE enumState);
    	MODE GetAppState(void);
    private:
    	MODE m_enumState;
    };
    

    but I get this errormessage: error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' [insert witty comment here] bdiamond

    N D M 3 Replies Last reply
    0
    • B BlackDice

      I have an enum that I'm trying to declare in my App, that will be accessed by the other dialogs and such in the project. However I keep getting the following error message: error C2061: syntax error :identifier 'MODE' I've tried to do this before and ended up doing a workaround. I'd rather do it the right way and have never seemed to get the hang of it. Here's what I have in my class definition, with the line it specifies in bold: class CBugReporterApp : public CWinApp { public: CBugReporterApp(); enum _MODE {NEWMODE,EDITMODE,BROWSEMODE} ; _MODE MODE; // Overrides public: virtual BOOL InitInstance(); // Implementation afx_msg void OnAppAbout(); DECLARE_MESSAGE_MAP() **void SetAppState(MODE enumState);** MODE GetAppState(void); private: MODE m_enumState; }; I know it's something very stupid, but I can't figure out what I'm doing wrong. Any help would be appreciated. Thanks in advance [insert witty comment here] bdiamond

      G Offline
      G Offline
      Gil Clark
      wrote on last edited by
      #4

      The problem is, as the code is currently written, MODE is a member variable of type _MODE. You are trying to use this member variable (MODE) instead of the type (_MODE) for parameters and other variables. Either change the functions to use _MODE instead of MODE or use a typedef like: typedef _MODE MODE;

      1 Reply Last reply
      0
      • B BlackDice

        I tried that first with just 'MODE' as the name of the enum like this:

        class CBugReporterApp : public CWinApp
        {
        public:
        	CBugReporterApp();
        	enum MODE {NEWMODE,EDITMODE,BROWSEMODE} ;
        
        	
        
        
        // Overrides
        public:
        	virtual BOOL InitInstance();
        
        // Implementation
        	afx_msg void OnAppAbout();
        	DECLARE_MESSAGE_MAP()
        	void SetAppState(MODE enumState);
        	MODE GetAppState(void);
        private:
        	MODE m_enumState;
        };
        

        but I get this errormessage: error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' [insert witty comment here] bdiamond

        N Offline
        N Offline
        Navin
        wrote on last edited by
        #5

        error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' What line generates that error? That seems to be something else - this code fragment looks much closer to being correct than the first one you posted. An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

        B 1 Reply Last reply
        0
        • B BlackDice

          I tried that first with just 'MODE' as the name of the enum like this:

          class CBugReporterApp : public CWinApp
          {
          public:
          	CBugReporterApp();
          	enum MODE {NEWMODE,EDITMODE,BROWSEMODE} ;
          
          	
          
          
          // Overrides
          public:
          	virtual BOOL InitInstance();
          
          // Implementation
          	afx_msg void OnAppAbout();
          	DECLARE_MESSAGE_MAP()
          	void SetAppState(MODE enumState);
          	MODE GetAppState(void);
          private:
          	MODE m_enumState;
          };
          

          but I get this errormessage: error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' [insert witty comment here] bdiamond

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #6

          You'll need to provide the relevant code for the GetAppState() method.


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          B 2 Replies Last reply
          0
          • D David Crow

            You'll need to provide the relevant code for the GetAppState() method.


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            B Offline
            B Offline
            BlackDice
            wrote on last edited by
            #7

            in looking at the above message where I just declare the enum as 'MODE', here's what I have:

            MODE CBugReporterApp::GetAppState(void)
            {
            	return m_enumState;
            }
            

            and here's the line it's now crashing on in my UI handler for a menu button: pCmdUI->Enable(theApp.GetAppState() == CBugReporterApp::BROWSEMODE); [insert witty comment here] bdiamond

            D 1 Reply Last reply
            0
            • N Navin

              error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' What line generates that error? That seems to be something else - this code fragment looks much closer to being correct than the first one you posted. An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.

              B Offline
              B Offline
              BlackDice
              wrote on last edited by
              #8

              please see post below in response to DavidCrow's question. Thanks!! [insert witty comment here] bdiamond

              1 Reply Last reply
              0
              • D David Crow

                You'll need to provide the relevant code for the GetAppState() method.


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                B Offline
                B Offline
                BlackDice
                wrote on last edited by
                #9

                Even when I comment out the UI handler code I get the following errors:

                error C2143: syntax error :missing ';'before 'CBugReporterApp::GetAppState'
                
                error C2556: 'int CBugReporterApp::GetAppState(void)' : overloaded function differs only by return type from 'CBugReporterApp::MODE CBugReporterApp::GetAppState(void)'
                
                 error C2501: 'MODE' : missing storage-class or type specifiers
                
                 error C2371: 'CBugReporterApp::GetAppState' : redefinition; different basic types
                

                [insert witty comment here] bdiamond

                1 Reply Last reply
                0
                • B BlackDice

                  in looking at the above message where I just declare the enum as 'MODE', here's what I have:

                  MODE CBugReporterApp::GetAppState(void)
                  {
                  	return m_enumState;
                  }
                  

                  and here's the line it's now crashing on in my UI handler for a menu button: pCmdUI->Enable(theApp.GetAppState() == CBugReporterApp::BROWSEMODE); [insert witty comment here] bdiamond

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  At the time the compiler encounters the MODE type, it does not know "who" it belongs to since the GetAppState() method is defined outside of the class declaration. So, you can either put the definition of the GetAppState() method inside of the class declaration, or you can qualify the MODE type by prefacing it with CBugReporterApp. Make sense?


                  "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                  B 1 Reply Last reply
                  0
                  • D David Crow

                    At the time the compiler encounters the MODE type, it does not know "who" it belongs to since the GetAppState() method is defined outside of the class declaration. So, you can either put the definition of the GetAppState() method inside of the class declaration, or you can qualify the MODE type by prefacing it with CBugReporterApp. Make sense?


                    "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                    B Offline
                    B Offline
                    BlackDice
                    wrote on last edited by
                    #11

                    Yes, that makes sense and I changed it and it works for that problem. However I'm still getting this message for the UI update function that I showed earlier: error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' As you can see from my class definition, the function is declared as public, so what the heck is it talking about? I don't mean to be a nuisance, but I've gone too long making band-aids for certain problems or just getting something to work and not knowing why. [insert witty comment here] bdiamond

                    D 1 Reply Last reply
                    0
                    • B BlackDice

                      Yes, that makes sense and I changed it and it works for that problem. However I'm still getting this message for the UI update function that I showed earlier: error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' As you can see from my class definition, the function is declared as public, so what the heck is it talking about? I don't mean to be a nuisance, but I've gone too long making band-aids for certain problems or just getting something to work and not knowing why. [insert witty comment here] bdiamond

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #12

                      bdiamond wrote: However I'm still getting this message for the UI update function that I showed earlier: Show me the whole function and I'll give it a look.


                      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                      B 1 Reply Last reply
                      0
                      • D David Crow

                        bdiamond wrote: However I'm still getting this message for the UI update function that I showed earlier: Show me the whole function and I'll give it a look.


                        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                        B Offline
                        B Offline
                        BlackDice
                        wrote on last edited by
                        #13

                        here's the function:

                        void CMainFrame::OnUpdateMaintenance(CCmdUI *pCmdUI)
                        {
                        	pCmdUI->Enable();
                        	pCmdUI->Enable(theApp.GetAppState() == theApp.BROWSEMODE);
                        }
                        

                        I've also tried it with int i = (int)theApp.GetAppState(); and I still get the same error [insert witty comment here] bdiamond :zzz:

                        D 1 Reply Last reply
                        0
                        • B BlackDice

                          here's the function:

                          void CMainFrame::OnUpdateMaintenance(CCmdUI *pCmdUI)
                          {
                          	pCmdUI->Enable();
                          	pCmdUI->Enable(theApp.GetAppState() == theApp.BROWSEMODE);
                          }
                          

                          I've also tried it with int i = (int)theApp.GetAppState(); and I still get the same error [insert witty comment here] bdiamond :zzz:

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #14

                          I think you would be better served my adding three "status" methods to your CBugReporterApp class. Something like:

                          class CBugReporterApp : public CWinApp
                          {
                          public:
                          bool IsNewMode( void ) { return NEWMODE == m_enumState; }
                          bool IsEditMode( void ) { return EDITMODE == m_enumState; }
                          bool IsBrowseMode( void ) { return BROWSEMODE == m_enumState; }
                          };

                          Does this help?


                          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                          1 Reply Last reply
                          0
                          • B BlackDice

                            I tried that first with just 'MODE' as the name of the enum like this:

                            class CBugReporterApp : public CWinApp
                            {
                            public:
                            	CBugReporterApp();
                            	enum MODE {NEWMODE,EDITMODE,BROWSEMODE} ;
                            
                            	
                            
                            
                            // Overrides
                            public:
                            	virtual BOOL InitInstance();
                            
                            // Implementation
                            	afx_msg void OnAppAbout();
                            	DECLARE_MESSAGE_MAP()
                            	void SetAppState(MODE enumState);
                            	MODE GetAppState(void);
                            private:
                            	MODE m_enumState;
                            };
                            

                            but I get this errormessage: error C2248: 'CBugReporterApp::GetAppState' : cannot access protected member declared in class 'CBugReporterApp' [insert witty comment here] bdiamond

                            M Offline
                            M Offline
                            mahade1
                            wrote on last edited by
                            #15

                            Your header file seems fine. I think the problem is in the implementation of your GetAppState(); (your cpp file). If you dont believe me, try commenting the source within GetAppState(). you wont get any errors. Try checking that function instead. Regards, Maha

                            1 Reply Last reply
                            0
                            • B BlackDice

                              I have an enum that I'm trying to declare in my App, that will be accessed by the other dialogs and such in the project. However I keep getting the following error message: error C2061: syntax error :identifier 'MODE' I've tried to do this before and ended up doing a workaround. I'd rather do it the right way and have never seemed to get the hang of it. Here's what I have in my class definition, with the line it specifies in bold: class CBugReporterApp : public CWinApp { public: CBugReporterApp(); enum _MODE {NEWMODE,EDITMODE,BROWSEMODE} ; _MODE MODE; // Overrides public: virtual BOOL InitInstance(); // Implementation afx_msg void OnAppAbout(); DECLARE_MESSAGE_MAP() **void SetAppState(MODE enumState);** MODE GetAppState(void); private: MODE m_enumState; }; I know it's something very stupid, but I can't figure out what I'm doing wrong. Any help would be appreciated. Thanks in advance [insert witty comment here] bdiamond

                              T Offline
                              T Offline
                              Tim Smith
                              wrote on last edited by
                              #16

                              Never declare anything after using DECLARE_MESSAGE_MAP or DECLARE_DYN* (all the MFC macros) without resetting your access. They change the access setting of your class. Place a new "public:" prior to the definition of SetAppState and GetAppState. (Well, that and fixing the _MODE problem which you have already done.) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                              B 1 Reply Last reply
                              0
                              • T Tim Smith

                                Never declare anything after using DECLARE_MESSAGE_MAP or DECLARE_DYN* (all the MFC macros) without resetting your access. They change the access setting of your class. Place a new "public:" prior to the definition of SetAppState and GetAppState. (Well, that and fixing the _MODE problem which you have already done.) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                                B Offline
                                B Offline
                                BlackDice
                                wrote on last edited by
                                #17

                                OK, thanks. I will put this in my notekeeper for future reference. [insert witty comment here] bdiamond :zzz:

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups