header problem(most likely)
Jun 20, 2014 at 6:05pm UTC
Hi, I cant find the error in my code even though i believe it to be a header problem.The bold underlined part of the code is what i believe to be causing the problem.
Error:
D:\qt\Tools\QtCreator\bin\untitled\city.h:11: Fehler: ISO C++ forbids declaration of 'zorro' with no type [-fpermissive]
virtual zorro(QGraphicsScene &scene);
^
City.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#ifndef CITY_H
#define CITY_H
#include "ui_mainwindow.h"
class city
{
public :
city(float &x,float &y);
virtual float getx();
virtual float gety();
virtual ~city();
virtual zorro(QGraphicsScene &scene);
private :
float x;
float y;
};
#endif // CITY_H
city.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include "city.h"
city::city(float &xkord,float &ykord)
{
x=xkord;
y=ykord;
}
float city::getx()
{
return this ->x;
}
float city::gety()
{
return this ->y;
}
city::zorro(QGraphicsScene &scene)
{
}
city::~city()
{
delete &x;
delete &y;
}
mainwindow.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QGraphicsScene *scene;
scene= new QGraphicsScene(0, 0, 500, 500);
ui->setupUi(this );
connect(ui->actionClose, SIGNAL(triggered()), this , SLOT(close()));
scene->addEllipse (100 , 100 , 4, 4, QPen (Qt :: red), QBrush (Qt :: red , Qt :: SolidPattern ));
ui->graphicsView->setScene(scene);
ui->graphicsView->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
}
mainwindow.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <city.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public :
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private :
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
I am using qt creator and this is the entire project(atlest the files i have access too). The goal of the project is to create a little map with dots representing cities.I hope someone can help me fix this problem.
Jun 20, 2014 at 6:10pm UTC
All functions (except constructors and destructors) must specify a return type.
virtual /*missing return type goes here*/ zorro(QGraphicsScene &scene);
Hope this helps.
Jun 20, 2014 at 6:18pm UTC
Thanks Duoas I was so sure that it had to be a header problem that i forgot to look for the most basic mistakes.
Topic archived. No new replies allowed.