c++ - undefined-reference Error when defining a function in the *.cpp instead of in the *.h -


i have got problem: have 2 classes: mainwindow , ergebnisausfortran this:

mainwindow.h:

    #ifndef mainwindow_h     #define mainwindow_h        #include <qmainwindow>     #include <qdebug>     #include <qstring>     #include "ergbnisausfortran.h"              namespace ui {     class mainwindow;     }      class mainwindow : public qmainwindow     {         q_object      public:         explicit mainwindow(qwidget *parent = 0);         ~mainwindow();              public:         ergbnisausfortran berechnung();                 ergbnisausfortran berechnung_1()         {            ergbnisausfortran ret;            qdebug() << " ich berechne berechnung_1..." ;                           return ret;         }      private slots:         void on_pb_calculate_clicked();            private:         ui::mainwindow *ui;     };      #endif // mainwindow_h 

mainwindow.cpp:

#include "mainwindow.h" #include "ui_mainwindow.h" #include "ergbnisausfortran.h"  mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this); }  mainwindow::~mainwindow() {     delete ui; }   void mainwindow::on_pb_calculate_clicked() {      ergbnisausfortran ergebnis_1;      ergbnisausfortran ergebnis;      ergebnis_1 = berechnung_1();      ergebnis = berechnung(); }  ergbnisausfortran berechnung() {     ergbnisausfortran ret;     qdebug() << " ich berechne..." ;     return ret; } 

the thing puzzles me following:

i have 2 methods berechnung() , berechnung_1().

berechnung() declared in mainwindow.h , defined in mainwindow.cpp

berechnung_1() declared in mainwindow.h , defined in mainwindow.h

when run program following error concerning berechnung():

undefined reference mainwindow::berechnung().berechnung_1 works well. puzzles me because include mainwindow.h in mainwindow.cpp.

does know wrong?

thank

itelly

you forgot qualify name of member function:

ergbnisausfortran mainwindow::berechnung()                   ^^^^^^^^^^^^ 

so instead declared new non-member function, leaving member function undefined.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -