expected class-name error

  • 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

  • Lifetime Qt Champion

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

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

  • Lifetime Qt Champion


    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"

  • @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?

  • Lifetime Qt Champion


    Can you also post the content of node.h

  • Lifetime Qt Champion

    @Niagarer said in expected class-name error:

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

    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)

    Yes, the problem was a bit bigger.

    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):

    Thanks for your help!!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.