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. UPDATE CLOSED error: declaration of anonymous class must be a definition

UPDATE CLOSED error: declaration of anonymous class must be a definition

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncement
7 Posts 3 Posters 37 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    This post original subject - error: declaration of anonymous class must be a definition was caused by this class declaration

    < class REG_EXP //regular_expression_class
    {
    int a;
    QString text;
    QString RegExp;
    QString Analyze;
    } TEST_REG_EXP;
    /pre>

    Search for the symbol "REG_EXP" in the entire project returned no result.
    The conclusion
    it is unknown why the error was posted.
    Please consider this matter closed.

    K R 2 Replies Last reply
    0
    • L Lost User

      This post original subject - error: declaration of anonymous class must be a definition was caused by this class declaration

      < class REG_EXP //regular_expression_class
      {
      int a;
      QString text;
      QString RegExp;
      QString Analyze;
      } TEST_REG_EXP;
      /pre>

      Search for the symbol "REG_EXP" in the entire project returned no result.
      The conclusion
      it is unknown why the error was posted.
      Please consider this matter closed.

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      What the compiler is trying to tell you is that you have an invalid function definition, namely

      void PassTrace(class *Pointer);

      Think about that a little bit. What is the type of Pointer? If your definition of PassTrace (i.e. the place where you provide the code for the function) matches the given declaration, how would you access any of Pointer's members? Does the class have member a, or a member name, value? There's no way to know. Perhaps you meant

      void PassTrace(Test *Pointer)

      or maybe you want a Template?

      template
      void PassTrace
      {
      // body of function
      }

      If you know that you'll never need to test *Pointer for null, you might consider using a reference rather than a pointer, and if you're not going to change the contents of what Pointer points to, then consider marking it as const as well. Other than that, passing a pointer to a class (or struct) is no different that passing a pointer to anything else:

      class myClass {
      // class members ...
      };

      void f(myClass *pointer)
      {
      // function body
      }

      int main()
      {
      myClass c;
      // instantiate c's data members
      f(&c); // call f with a pointer to object of type myClass
      }

      "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

      L 1 Reply Last reply
      0
      • K k5054

        What the compiler is trying to tell you is that you have an invalid function definition, namely

        void PassTrace(class *Pointer);

        Think about that a little bit. What is the type of Pointer? If your definition of PassTrace (i.e. the place where you provide the code for the function) matches the given declaration, how would you access any of Pointer's members? Does the class have member a, or a member name, value? There's no way to know. Perhaps you meant

        void PassTrace(Test *Pointer)

        or maybe you want a Template?

        template
        void PassTrace
        {
        // body of function
        }

        If you know that you'll never need to test *Pointer for null, you might consider using a reference rather than a pointer, and if you're not going to change the contents of what Pointer points to, then consider marking it as const as well. Other than that, passing a pointer to a class (or struct) is no different that passing a pointer to anything else:

        class myClass {
        // class members ...
        };

        void f(myClass *pointer)
        {
        // function body
        }

        int main()
        {
        myClass c;
        // instantiate c's data members
        f(&c); // call f with a pointer to object of type myClass
        }

        "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

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

        Thank you, appreciate your reply. I did JUST modify my working test function and do not see why my definition is wrong. I am obviously missing something VERY basic here. Should it work this way ? void BT_Utility_Library::PassTrace(class *) // { // //qDebug()< // void BT_Utility_Library::PassTrace(class *Pointer) // { // //qDebug()<

        L K 2 Replies Last reply
        0
        • L Lost User

          Thank you, appreciate your reply. I did JUST modify my working test function and do not see why my definition is wrong. I am obviously missing something VERY basic here. Should it work this way ? void BT_Utility_Library::PassTrace(class *) // { // //qDebug()< // void BT_Utility_Library::PassTrace(class *Pointer) // { // //qDebug()<

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

          void BT_Utility_Library::PassTrace(class *)

          You cannot have a pointer that has no definition. The class keyword is usaed to define an actual class, whether abstract or not. In the definition above the pointer must be of an actual class so the compiler knows what to do with any statements that use it.

          1 Reply Last reply
          0
          • L Lost User

            This post original subject - error: declaration of anonymous class must be a definition was caused by this class declaration

            < class REG_EXP //regular_expression_class
            {
            int a;
            QString text;
            QString RegExp;
            QString Analyze;
            } TEST_REG_EXP;
            /pre>

            Search for the symbol "REG_EXP" in the entire project returned no result.
            The conclusion
            it is unknown why the error was posted.
            Please consider this matter closed.

            R Offline
            R Offline
            RedDk
            wrote on last edited by
            #5

            Sorry, what was the question?:thumbsdown:

            L 1 Reply Last reply
            0
            • L Lost User

              Thank you, appreciate your reply. I did JUST modify my working test function and do not see why my definition is wrong. I am obviously missing something VERY basic here. Should it work this way ? void BT_Utility_Library::PassTrace(class *) // { // //qDebug()< // void BT_Utility_Library::PassTrace(class *Pointer) // { // //qDebug()<

              K Offline
              K Offline
              k5054
              wrote on last edited by
              #6

              consider:

              class A { /* ... */ }
              class B { /* ... */ }
              class C { /* ... */ }

              void f(class *ptr);

              Which class does ptr refer to in void f(class *ptr)? The definition of void f(class *ptr) makes as much sense as void f(const i). There's no type associated with the parameter, so the compiler does not know what type the parameter is. Note: The use of class or struct for a variable/parameter declaration is optional in C++ :

              class C { /* ... */ }
              int main()
              {
              class C c1;
              C c2;
              }

              the declarations of c1 and c2 are both valid, and both declare a object of type class C

              "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

              1 Reply Last reply
              0
              • R RedDk

                Sorry, what was the question?:thumbsdown:

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

                error: declaration of anonymous class must be a definition and do not known how and where to correct this error. STAND BY I have another fish to fry and I need to rebuild this task from scratch. I took a wrong approach and that is why I got this error.

                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