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. C2061

C2061

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
9 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.
  • T Offline
    T Offline
    T RATHA KRISHNAN
    wrote on last edited by
    #1

    Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:

    class InitialMenu; //forward declaration
    class PlayMenu;

    class InitialMenu : public IEventReceiver
    {
    private:
    SAppContext &Context;
    PlayMenu *playMenu;
    public:
    InitialMenu(SAppContext &context) : Context(context)
    {
    }

         virtual bool OnEvent(const SEvent& event)
     {
          playMenu = new PlayMenu(Context);
    		 return true;
         }
    

    };

    class PlayMenu : public IEventReceiver
    {
    private:
    SAppContext &Context;
    InitialMenu* initialMenu;
    public:
    PlayMenu(SAppContext &context) : Context(context)
    {
    }
    virtual bool OnEvent(const SEvent& event)
    {
    initialMenu = new initialMenu(Context);
    return true;
    }
    };

    How to resolve this error?

    _ A L S T 5 Replies Last reply
    0
    • T T RATHA KRISHNAN

      Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:

      class InitialMenu; //forward declaration
      class PlayMenu;

      class InitialMenu : public IEventReceiver
      {
      private:
      SAppContext &Context;
      PlayMenu *playMenu;
      public:
      InitialMenu(SAppContext &context) : Context(context)
      {
      }

           virtual bool OnEvent(const SEvent& event)
       {
            playMenu = new PlayMenu(Context);
      		 return true;
           }
      

      };

      class PlayMenu : public IEventReceiver
      {
      private:
      SAppContext &Context;
      InitialMenu* initialMenu;
      public:
      PlayMenu(SAppContext &context) : Context(context)
      {
      }
      virtual bool OnEvent(const SEvent& event)
      {
      initialMenu = new initialMenu(Context);
      return true;
      }
      };

      How to resolve this error?

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You should split the class declarations into header files and class definitions into CPP files.

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • T T RATHA KRISHNAN

        Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:

        class InitialMenu; //forward declaration
        class PlayMenu;

        class InitialMenu : public IEventReceiver
        {
        private:
        SAppContext &Context;
        PlayMenu *playMenu;
        public:
        InitialMenu(SAppContext &context) : Context(context)
        {
        }

             virtual bool OnEvent(const SEvent& event)
         {
              playMenu = new PlayMenu(Context);
        		 return true;
             }
        

        };

        class PlayMenu : public IEventReceiver
        {
        private:
        SAppContext &Context;
        InitialMenu* initialMenu;
        public:
        PlayMenu(SAppContext &context) : Context(context)
        {
        }
        virtual bool OnEvent(const SEvent& event)
        {
        initialMenu = new initialMenu(Context);
        return true;
        }
        };

        How to resolve this error?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If you look at the line that the error refers to you may notice the incorrect constructor call thus:

        initialMenu = new initialMenu(Context);
        

        It's time for a new signature.

        A 1 Reply Last reply
        0
        • T T RATHA KRISHNAN

          Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:

          class InitialMenu; //forward declaration
          class PlayMenu;

          class InitialMenu : public IEventReceiver
          {
          private:
          SAppContext &Context;
          PlayMenu *playMenu;
          public:
          InitialMenu(SAppContext &context) : Context(context)
          {
          }

               virtual bool OnEvent(const SEvent& event)
           {
                playMenu = new PlayMenu(Context);
          		 return true;
               }
          

          };

          class PlayMenu : public IEventReceiver
          {
          private:
          SAppContext &Context;
          InitialMenu* initialMenu;
          public:
          PlayMenu(SAppContext &context) : Context(context)
          {
          }
          virtual bool OnEvent(const SEvent& event)
          {
          initialMenu = new initialMenu(Context);
          return true;
          }
          };

          How to resolve this error?

          A Offline
          A Offline
          Aescleal
          wrote on last edited by
          #4

          Without knowing which line the error happened at it's a bit hard working out why you're getting that error. Having said thay if you implement your classes the way you do within the same translation unit you'll never get it to work - you've got a cyclic depenedency between the two clases. Each has to know the size of the other to be able to create instances of the other. Split them up into pairs of .h and .cpp files and it'll have a better chance of working. Oh, and remember to implement destructors or use some sort of resource management class instead of the pointers. And beware of any class that calls itself a context (or manager) they're usually global state in disguise. Cheers, Ash

          1 Reply Last reply
          0
          • L Lost User

            If you look at the line that the error refers to you may notice the incorrect constructor call thus:

            initialMenu = new initialMenu(Context);
            

            It's time for a new signature.

            A Offline
            A Offline
            Aescleal
            wrote on last edited by
            #5

            Good spot - I'm surprised that he's not getting an error message about trying to create a PlayMenu when the class has been declared but not defined but I completely missed the typo. Cheers, Ash

            L 1 Reply Last reply
            0
            • A Aescleal

              Good spot - I'm surprised that he's not getting an error message about trying to create a PlayMenu when the class has been declared but not defined but I completely missed the typo. Cheers, Ash

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              As you said in a previous post: "who teaches this stuff?". ;)

              It's time for a new signature.

              1 Reply Last reply
              0
              • T T RATHA KRISHNAN

                Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:

                class InitialMenu; //forward declaration
                class PlayMenu;

                class InitialMenu : public IEventReceiver
                {
                private:
                SAppContext &Context;
                PlayMenu *playMenu;
                public:
                InitialMenu(SAppContext &context) : Context(context)
                {
                }

                     virtual bool OnEvent(const SEvent& event)
                 {
                      playMenu = new PlayMenu(Context);
                		 return true;
                     }
                

                };

                class PlayMenu : public IEventReceiver
                {
                private:
                SAppContext &Context;
                InitialMenu* initialMenu;
                public:
                PlayMenu(SAppContext &context) : Context(context)
                {
                }
                virtual bool OnEvent(const SEvent& event)
                {
                initialMenu = new initialMenu(Context);
                return true;
                }
                };

                How to resolve this error?

                S Offline
                S Offline
                sunlin7
                wrote on last edited by
                #7

                I think your spelling wrong:

                              virtual bool OnEvent(const SEvent& event)
                	  {
                               initialMenu = new initialMenu(Context);
                				  return true;
                              } 
                
                              virtual bool OnEvent(const SEvent& event)
                	  {
                               initialMenu = new InitialMenu(Context);
                				  return true;
                              }
                
                S 1 Reply Last reply
                0
                • S sunlin7

                  I think your spelling wrong:

                                virtual bool OnEvent(const SEvent& event)
                  	  {
                                 initialMenu = new initialMenu(Context);
                  				  return true;
                                } 
                  
                                virtual bool OnEvent(const SEvent& event)
                  	  {
                                 initialMenu = new InitialMenu(Context);
                  				  return true;
                                }
                  
                  S Offline
                  S Offline
                  sunlin7
                  wrote on last edited by
                  #8

                  Sorry for my spelling.^_^

                  1 Reply Last reply
                  0
                  • T T RATHA KRISHNAN

                    Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:

                    class InitialMenu; //forward declaration
                    class PlayMenu;

                    class InitialMenu : public IEventReceiver
                    {
                    private:
                    SAppContext &Context;
                    PlayMenu *playMenu;
                    public:
                    InitialMenu(SAppContext &context) : Context(context)
                    {
                    }

                         virtual bool OnEvent(const SEvent& event)
                     {
                          playMenu = new PlayMenu(Context);
                    		 return true;
                         }
                    

                    };

                    class PlayMenu : public IEventReceiver
                    {
                    private:
                    SAppContext &Context;
                    InitialMenu* initialMenu;
                    public:
                    PlayMenu(SAppContext &context) : Context(context)
                    {
                    }
                    virtual bool OnEvent(const SEvent& event)
                    {
                    initialMenu = new initialMenu(Context);
                    return true;
                    }
                    };

                    How to resolve this error?

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #9

                    dear radha, can you please consult MSDN and google, before posting your query here!, if you type C2061 in MSDN, it will let you know, why it's throwing the error!

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                    Never mind - my own stupidity is the source of every "problem" - Mixture

                    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                    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