Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. expected class-name error
Forum Updated to NodeBB v4.3 + New Features

expected class-name error

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 9.0k Views 2 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.
  • NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on last edited by Niagarer
    #1

    Hey,
    I have built this class:

    #ifndef FUNCTIONNODE_H
    #define FUNCTIONNODE_H
    
    #include "node.h"
    
    class FunctionNode : public Node
    {}; //error here
    #endif // FUNCTIONNODE_H
    

    And get this error:

    error: expected class-name before '{' token
     {
     ^
    

    And I don't know why. The class name is there, so the mistake is different to the error I think, but I got no other errors.
    Any ideas?
    Thanks for answers

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      are you sure it knows Node ?
      and its not node or anything like that ?

      NiagarerN 1 Reply Last reply
      0
      • mrjjM mrjj

        are you sure it knows Node ?
        and its not node or anything like that ?

        NiagarerN Offline
        NiagarerN Offline
        Niagarer
        wrote on last edited by Niagarer
        #3

        I added

        class Node;
        

        and now I get this:

         error: invalid use of incomplete type 'class Node'
         class FunctionNode : public Node
                                     ^
        

        Looks like you are right, it didn't know class Node but I unfortunately don't know what this really means... why is it incomplete type? Class Node is a QGraphicsItem derived class.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi

          this compiles fine here
          class TestNode{};
          class TestNodeChild : TestNode {
          };

          Incomplete means "Hey you only told me the class name"
          Nothing more.
          And that is not so good with inheritance as it needs to know base class ctor etc.

          When you do
          class node;
          That is a forward. And tells only name.
          It speed up compilation when allowed.
          The cure is full include
          #include "node.h"

          NiagarerN 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi

            this compiles fine here
            class TestNode{};
            class TestNodeChild : TestNode {
            };

            Incomplete means "Hey you only told me the class name"
            Nothing more.
            And that is not so good with inheritance as it needs to know base class ctor etc.

            When you do
            class node;
            That is a forward. And tells only name.
            It speed up compilation when allowed.
            The cure is full include
            #include "node.h"

            NiagarerN Offline
            NiagarerN Offline
            Niagarer
            wrote on last edited by
            #5

            @mrjj
            Ok... This is weird because I did include node.h . What does it need more?
            It has the class name and the header file. Is there a problem, that Node derives from QGraphicsItem or sth?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Can you also post the content of node.h

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Niagarer said in expected class-name error:

                Is there a problem, that Node derives from QGraphicsItem or sth?

                Nope.
                Unless the .h have some error that prevents parsing, then it should be fine.

                But as mr sgaist says, please show whole file so we can see if we spot it.

                I assume its not just because in .h file node and you use Node. (big vs small letters)

                1 Reply Last reply
                1
                • NiagarerN Offline
                  NiagarerN Offline
                  Niagarer
                  wrote on last edited by
                  #8

                  SOLUTION
                  Yes, the problem was a bit bigger.

                  Summarized:
                  It was a problem with including other classes in the header files of the classes. The solution is, to use forward declaration ( class myClass; ) and include the myclass.h in the source (.cpp) file, not in the header file. I did not do this consequent and so, my derived class knew the parent class but thought, it would not have any content. Why, is good explained here (look to the answer post by Ben Voigt):
                  https://stackoverflow.com/questions/5319906/error-expected-class-name-before-token

                  Thanks for your help!!

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved