How to use Global Functions correctly? (Undefined reference)
-
Hello, i´ve tried to write a program for different sort algorithm.
As soon as i tried to add a Function to Global im getting errors. Before the code worked fine. so the issue should be by one of the followings, but i dont know what causes the issue, but its always if the program try to open the (Ausgabe)Function in a Function:
frmmain.cpp
void Ausgabe(QVector<int> &ausgabe, QVector<int> &sort, QListWidget *lwSort, QListWidget *lwArray, int &anzahl, bool &sortierer);
void Ausgabe(QVector<int> &array, QVector<int> &sort, QListWidget *lwSort, QListWidget *lwArray, int &anzahl, bool &sortierer) { if(sortierer == false) { for(int i=0; i <= anzahl-1; i++) { lwArray->addItem(QString::number(array[i])); } } else { for(int i=0; i <= anzahl-1; i++) { lwSort->addItem(QString::number(sort[i])); } } sortierer = false; }
void FrmMain::on_btnBubble_clicked() { sortierer = true; BubbleSortASC(sort, tempVector, anzahl); Ausgabe(array, sort, ui->lwSort, ui->lwArray, anzahl, sortierer); }
frmmain.h
private slots: void on_btnArray_clicked(); void on_cbSortiert_clicked(); void on_cbOrderBy_clicked(); void on_cbFirst_clicked(); void Ausgabe(QVector<int> &array, QVector<int> &sort, QListWidget *lwSort, QListWidget *lwArray, int &anzahl, bool &sortierer); void on_btnBubble_clicked(); private: Ui::FrmMain *ui; bool asc = false; bool desc = false; bool first = false; bool sortierer = false; QVector<int> tempVector; QVector<int> array; QVector<int> sort; int anzahl; };
-
You have a private slot member function with the same name ("Ausgabe") and the same parameters.
When you callAusgabe
inFrmMain::on_btnBubble_clicked
, the compiler will try to callFrmMain::Ausgabe(...)
which I think you probably have not implemented...
If I'm right, just delete thevoid Ausgabe(...)
defined infrmmain.h
.
Little tip: If you have both a global function and a class member function with the same name and parameters, and you want to call the global function inside the class, then you need to add::
, for example:::Ausgabe(...)
-
You have a private slot member function with the same name ("Ausgabe") and the same parameters.
When you callAusgabe
inFrmMain::on_btnBubble_clicked
, the compiler will try to callFrmMain::Ausgabe(...)
which I think you probably have not implemented...
If I'm right, just delete thevoid Ausgabe(...)
defined infrmmain.h
.
Little tip: If you have both a global function and a class member function with the same name and parameters, and you want to call the global function inside the class, then you need to add::
, for example:::Ausgabe(...)