I have some classes in my project, and when I try to compile my code, I am getting an error:
invalid use of incomplete type "class GameObject"
... when trying to inherit from GameObject
. I have all #include
s and forward declarations, but still have a problem. How do I solve it?
gameobject.h
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
#include "mainwindow.h"
class MainWindow;
class GameObject // base class
{
public:
GameObject();
QPoint getStartPos() const;
QPoint getEndPos() const;
protected:
std::string url;
QLabel* label;
MainWindow* window;
QPoint startPos;
QPoint endPos;
};
#endif // GAMEOBJECT_H
barrirer.h
#ifndef BARRIRER_H
#define BARRIRER_H
#include "gameobject.h"
#include "mainwindow.h"
#include <QLabel>
#include <QPoint>
class MainWindow;
class GameObject;
class Barrier : public GameObject // derived class, error here
{
public:
Barrier(QLabel* _label, QPoint _startPos, QPoint _endPos, MainWindow* _window);
bool isMovePosible(QPoint _startPos, QPoint _endPos);
bool isCrossed(QPoint _startPos, QPoint _endPos);
};
#endif // BARRIRER_H
mainwindow.h
part of it
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "barrier.h"
namespace Ui {
class MainWindow;
}
class Barrier;
class MainWindow : public QMainWindow
{
Q_OBJECT
It's not all mainwidow.h, but lower there is absolutely cannot be any problem, there's no usage of GameObject in MainWindow