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 -
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.
-
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" -
Hi,
Can you also post the content of
node.h
-
@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)
-
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-tokenThanks for your help!!