C2143: syntax error: missing ';' before '*'

The next bit of code causes an error. I have no idea why. Can anyone shed some light? All codes are in different files.

#ifndef MAINSESSION_H #define MAINSESSION_H #include "sessionsuper.h" #include "mainwindow.h" class MainSession : public SessionSuper { public: MainSession(); private: }; #include "mainsession.h" MainSession::MainSession() { } #endif // MAINSESSION_H #ifndef MAINWINDOW_H #define MAINWINDOW_H #include "mainsession.h" #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; MainSession *ms; //Error here }; #endif // MAINWINDOW_H #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //ms=new MainSession(this); } MainWindow::~MainWindow() { delete ui; } #ifndef SESSIONSUPER_H #define SESSIONSUPER_H class SessionSuper { public: SessionSuper(); }; #endif // SESSIONSUPER_H #include "sessionsuper.h" SessionSuper::SessionSuper() { } 

Error:

d: \ qtsrc \ untitled4 \ mainwindow.h: 20: error: C2143: syntax error: missing ';' before '*'

d: \ qtsrc \ untitled4 \ mainwindow.h: 20: error: C4430: missing specifier type - int. Note: C ++ does not support default-int d: \ qtsrc \ untitled4 \ mainwindow.h: 20: error: C4430: there is no specifier - int type. Note: C ++ does not support default-int

Am uses the Qt + msvc10.0 compiler.

Update: -

 #ifndef MAINSESSION_H #define MAINSESSION_H #include "sessionsuper.h" #include "mainwindow.h" class MainSession : public SessionSuper { public: MainSession(MainWindow*); private: MainWindow *mw; }; #endif // MAINSESSION_H #ifndef MAINWINDOW_H #define MAINWINDOW_H #include "mainsession.h" #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; MainSession *ms; }; #endif // MAINWINDOW_H #ifndef SESSIONSUPER_H #define SESSIONSUPER_H class SessionSuper { public: SessionSuper(); }; #endif // SESSIONSUPER_H #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } #include "mainsession.h" MainSession::MainSession(MainWindow mss) { mw=mss; } #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //ms=new MainSession(this); } MainWindow::~MainWindow() { delete ui; } #include "sessionsuper.h" SessionSuper::SessionSuper() { } 

Errors: - much more, but one type

+4
source share
3 answers

The problem is solved using the observer model.

Full demo here

Add a comment If you need a working code for the above code.

Hooray!!!

0
source

You have a circular include, Forward MainSession declaration to break the current circulation, include the problem.

In MainWindow.h

 //#include "mainsession.h" comment out this line class MainSession; // add forward declaration class MainWindow : public QMainWindow { //... MainSession *ms; //Error here. }; 
+4
source

I checked your code as follows:

 class MainWindow { public: explicit MainWindow(); ~MainWindow(); private: Ui::MainWindow *ui; MainSession *ms; //My error also here <- see this }; 

See here in my code where MainSession missing and I got the same error in the line. Hope this helps. MainSession may be missing a definition due to a missing file, a file not included, a problem with a scope (different namespace), etc. Please check them out. namespace Ui (in various ways) is probably the problem.

0
source

Source: https://habr.com/ru/post/1494253/


All Articles