0

Getting errors when including mainwindow.h (in my project it's called viewwindow.h) in other header file (in controller.h). Controller.h is located in folder Controller.

Errors that i got in viewwindow.h:

  1. C2143: syntax error: missing ';' before '*'
  2. C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  3. C2238: unexpected token(s) preceding ';'

And they all are pointing to line ControllerClass *pController;

If it's a stupid question then help me and smash that dislike button. I deserved it.

viewwindow.h

#pragma once
#include <QMainWindow>
#include "Controller/controllerclass.h"

namespace Ui {
class ViewWindow;
}

class ViewWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit ViewWindow(QWidget *parent = nullptr);
    ~ViewWindow();

private slots:
    void on_ExitAction_triggered();

private:

    // Main UI
    Ui::ViewWindow  *ui;

    // Controller sends user input to EditorFacade class
    ControllerClass *pController;
};

viewwindow.cpp

#include "viewwindow.h"
#include "ui_viewwindow.h"

ViewWindow::ViewWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ViewWindow)
{
    ui->setupUi(this);

    pController = new ControllerClass();
}

ViewWindow::~ViewWindow()
{
    delete pController;
    delete ui;
}

void ViewWindow::on_ExitAction_triggered()
{
    QApplication::quit();
}

controllerclass.h

#pragma once
#include "viewwindow.h"

class ControllerClass;
class ControllerClass
{
public:

    ControllerClass();

};

controller.cpp

#include "controllerclass.h"

ControllerClass::ControllerClass()
{

}
Flone
  • 187
  • 1
  • 3
  • 11
  • This looks like a circular include path. `viewwindow.h` can't include `controllerclass.h` if `controllerclass.h` includes `viewwindow.h` – drescherjm Oct 30 '18 at 16:13
  • @dreschrjm but i need to include viewwindow.h in controller.h because i need to pass ui pointer to other class that being created by controller class. – Flone Oct 30 '18 at 16:15
  • Also next time copy the error message verbatim. If this is Visual Studio copy from the Output Tab not the Errors List since the output tab has the entire error as text. – drescherjm Oct 30 '18 at 16:16
  • 2
    You solve that using a forward declaration. – drescherjm Oct 30 '18 at 16:16
  • @drescherjm I copied errors from Qt Creator – Flone Oct 30 '18 at 16:18
  • 1
    @Flone Have you read the link of the duplicate question? In the most voted answer, clearly indicate the solution, the idea of marking as a duplicate is to indicate to the OP that the solution already exists and that it should use it, and this saves us all time: It saves time for you because you no longer wait for an answer, it already exists :-) , and time for us because we can focus on another question. – eyllanesc Oct 30 '18 at 16:24
  • @drescherjm thanks! – Flone Oct 30 '18 at 16:31
  • @eyllanesc thanks! – Flone Oct 30 '18 at 16:31

0 Answers0