[Moved] Wierd ISO C++ forbids delaration with no type error



  • I have been looking at this for over an hour and can't see the problem...and I am sure it is something right in front of my face. Here is the code:
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QSettings>

    //Forward declaration of classes used
    class NamePage;
    class AddressPage;
    class StartPage;

    namespace Ui {
    class MainWindow;

    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:
    void changeEvent(QEvent *e);
    void closeEvent (QCloseEvent *event);

    private:
    Ui::MainWindow *ui;
    NamePage *name;
    AddressPage *address;
    StartPage *startPage;//error here...ISO C++ forbids declaration of 'StartPage' with no type???

    #endif // MAINWINDOW_H@

    What am I missing? It is wierd that the forward declaration of my other classes works but for this one it doesn't.



  • You are certainly missing a closing brace for your class. Also, what compiler is this?



  • Opps, I cut the irrelevant code out and accidently cut out the closing brace and semicolon. I am using the QT Creator compiler, mingw?



  • It looks like the compiler doesn't recognize StartPage as a class. Maybe you should include the header of StartPage and make sure the compiler sees it.



  • [quote author="poporacer" date="1295531087"]Opps, I cut the irrelevant code out and accidently cut out the closing brace and semicolon. I am using the QT Creator compiler, mingw?[/quote]

    can you please post the complete header? I think there must be some other error that leads to this one.



  • Your snippet works for me. So, as Gerolf stated, there must be some other error.



  • I will post the complete header when I get home. I had another wierd error earlier this week where I added a button in designer and then when I ran the program it wasn't there. I tried clean qmake and then rebuild. It still didn't work. I ended up getting it to work by manually deleting all the build files....object files, make files etc and then run qmake and build. I tried it this time but it didn't work.
    Thanks for your help.



  • Real strange behaviour. If I change the forward declaration to some other name and the pointer declaration to match, it works. And when I change the header file and class declaration, the compiler doesn't highlight StartPage references as not being declared. Is it possible that StartPage is a function or class in either C++ or QT? The one thing that gives me doubts is that Volker tried the snippet and all is OK. Here is the complete header.
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QSettings>

    #include "address.h"
    #include "projects.h"

    //Forward declaration of classes used
    class AddressPage;
    class ProjectPage;
    class StartPage;
    namespace Ui {
    class MainWindow;

    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:
    void changeEvent(QEvent *e);
    void closeEvent (QCloseEvent *event);

    private:
    Ui::MainWindow *ui;
    ProjectPage *project;
    AddressPage *address;
    StartPage *startPage;
    void writeSettings();
    void readSettings() ;
    int idAddress;
    int idProject;
    QSettings *mSettings;

    signals:
    void restoreAddressCombo(int);
    void cmbAddressChange(int);
    void restoreProjectCombo(int);

    private slots:
    void on_btnSection_clicked();
    };

    #endif // MAINWINDOW_H
    @
    I tried this on another computer and got the same error. Any ideas?
    I am think I might just rename my class and all references. But I would like to know why it had the problem.
    Thanks a bunch. Any Ideas?



  • Seems to be a problem with these two includes:

    @
    #include "address.h"
    #include "projects.h"
    @

    I have to comment them, because they are not on my computer. The file compiles without errors here.



  • And as both are not used inside this header file, they should anyway not be included here...



  • I moved the headers, and I found that the problem might lie in the classes. They reference some classes that also use winserialport.h and other classes. I think there might be a class that uses startpage so I changed the class name and the associated files and all is well. Now I ran accross another problem. But I will start a new post. I am not sure if it should be in QT or here in C++ I think it should go in QT as the error references a qt file.

    Thanks for your help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.