Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    C++ forbids declaration...

    General and Desktop
    4
    4
    1663
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      leandrogs last edited by

      Hello everyone! I am developing this modeling software that user can choose two diferent types of model to fill the parameters and run. The problem is this, i have to instantiate two objects (two diferent models) but Qt insists generate the message error "ISO C++ forbids declaration of 'Coupled' with no type". I have already searched about this and i didn't found anything helpful. Part of my code is that shown below.

      dengueme.h:
      @#ifndef DENGUEME_H
      #define DENGUEME_H

      #include <QMainWindow>
      #include <QtGui>
      #include <QtCore>

      #include "integrated.h"
      #include "coupled.h"

      namespace Ui {
      class DengueME;
      }

      //class Coupled; --> i have tried this without success
      //class Integrated; --> i have tried this without success

      class DengueME : public QMainWindow
      {
      Q_OBJECT

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

      public slots:
      void loadCoupled();
      void loadIntegrated();
      void workspace();
      void runModel();

      private:
      Ui::DengueME *ui;
      QFileSystemModel *dirmodel;

      Integrated *i;
      Coupled *c;     // HERE IS MY PROBLEM 
      
      int model;
      

      };

      #endif // DENGUEME_H
      @

      dengueme.cpp:
      @#include "dengueme.h"
      #include "ui_dengueme.h"

      #include "coupled.h"
      #include "integrated.h"

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

      connect(this->ui->actionCoupled_Model, SIGNAL(triggered()), this, SLOT(loadCoupled()));
      connect(this->ui->actionIntegrated_Model, SIGNAL(triggered()), this, SLOT(loadIntegrated()));
      connect(this->ui->pushButton_run, SIGNAL(clicked()), this, SLOT(runModel()));
      
      workspace();
      

      }

      DengueME::~DengueME()
      {
      delete ui;
      }

      void DengueME::workspace()
      {
      dirmodel = new QFileSystemModel(this);

      QStringList filters;
      filters << "*.lua";
      dirmodel->setNameFilters(filters);
      
      this->ui->treeView->setModel(dirmodel);
      this->ui->treeView->setColumnHidden(1, true);
      this->ui->treeView->setColumnHidden(2, true);
      this->ui->treeView->setColumnHidden(3, true);
      
      this->ui->treeView->setRootIndex(
                  dirmodel->setRootPath(
                      QFileInfo(QCoreApplication::applicationFilePath()).filePath()
                      )
                  );
      

      }

      void DengueME::loadCoupled()
      {
      this->c = new Coupled();
      this->ui->scrollArea->setWidget(c);

      model = 0;
      

      }

      void DengueME::loadIntegrated()
      {
      this->i = new Integrated();
      this->ui->scrollArea->setWidget(i);

      model = 1;
      

      }

      void DengueME::runModel()
      {
      if(model == 0){
      this->ui->textBrowser_output->setText("Processing data...\n");
      // this->ui->textBrowser_output->setText(this->c->executeModel());
      } else if(model == 1) {
      this->ui->textBrowser_output->setText("Processing data...\n");
      this->ui->textBrowser_output->setText(this->i->executeModel());
      }
      }
      @

      coupled.h:
      @#ifndef WIDGET_H
      #define WIDGET_H

      #include <QWidget>
      #include <QtGui>

      namespace Ui {
      class Coupled;
      }

      class Coupled : public QWidget
      {
      Q_OBJECT

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

      public slots:
      // (...)

      private:
      Ui::Coupled *ui;
      };

      #endif // WIDGET_H
      @

      integrated.h:
      @#ifndef WIDGET_H
      #define WIDGET_H

      #include <QWidget>
      #include <QtGui>

      namespace Ui {
      class Integrated;
      }

      class Integrated : public QWidget
      {
      Q_OBJECT

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

      public slots:
      // (...)

      private:
      Ui::Integrated *ui;
      };

      #endif // WIDGET_H
      @

      Anyone have any idea about what should i do?

      Ps 1: I'm sorry about my english;
      Ps 2: Sorry if this topic looks like any other (i swear, i searched this A LOT!).

      1 Reply Last reply Reply Quote 0
      • A
        alexisdm last edited by

        The include guards have to be unique for each header file:
        @#ifndef WIDGET_H
        #define WIDGET_H@

        should be changed to something like:
        @#ifndef INTEGRATED_H
        #define INTEGRATED_H@

        in integrated.h.

        1 Reply Last reply Reply Quote 0
        • M
          MuldeR last edited by

          With modern compilers you should also be able to use a simple #prgame once instead of guards...

          http://en.wikipedia.org/wiki/Pragma_once

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply Reply Quote 0
          • U
            utcenter last edited by

            Old habits die hard.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post