[SOLVED] qtcreator "Expected class-name before '{' token"
-
Hello, I have a simple code, which, following a simple logic - must work. But I get that expected class-name before { token in my .h file. What is this??? Here is the code:
@
#include <QList>
#include "ActionEllipseItem.h"class ActionEllipseItem;
class MainWindow;class GameLogic {
friend class ActionEllipseItem;
friend class MaindWindow;
public:
virtual void checkConditions()=0;
virtual void getReport(ActionEllipseItem*) = 0;
virtual ~GameLogic()=0;
private:};
@And the class that must implement the functions:
@
#include "GameLogic.h"
#include "ActionEllipseItem.h"class ActionEllipseItem;
class GameOfNumbers : GameLogic { /* THE ERROR LINE*/
public:
void checkConditions();
void getReport(ActionEllipseItem*);
GameOfNumbers() ;
~GameOfNumbers();private:
};
@
Qt reports me this strange error. Really no idea why. -
You are using forward declaration for ActionEllipseItem, but you also include it's header file. One needs to be removed, in both header files.
You need to specify the mode of inheritance:
@
class GameOfNumbers : public GameLogic
// or
class GameOfNumbers : private GameLogic
@ -
It's not Qt reporting it. It's the compiler.
The odd thing I see is that you include ActionEllipseItem.h and then forward declare ActionEllipseItem. The point of forward declaration is so that you don't have to include the declaring header in another header. Maybe something in that header confuses the compiler?
Unrelated: Not an error, but you are not specifying the access type in your inheritance declaration. The default is private. Is that intended here? Even if so, I would still go for an explicit declaration for the future reader.
Also, a pure virtual destructor is also unusual. Not an error though.
-
Hi,
You forgot the access-specifier.
@
// Using the "public" access specifier:
class GameOfNumbers : public GameLogic {
...
};
@EDIT: Triple answer! :D
-
Hi,
you know that you don't use an access specifier? That would mean private inheritance and then, you can't access public stuff...[EDIT] Arrgh, so many people faster than me xD
-
Yes, I want to inherit all. It was not the public specifier. Mr Chris Kawa was right. It`s including the .h file. Thnaks, these C++ feats are confusing as hell!
-
bq. these C++ feats are confusing as hell!
Just at the beginning. Don't get discouraged ;)
-
Will try to do so...