[Solved]creat functions in mainwindow.cpp
-
Hello can someone please explain to me how to declare function if I need calculate something .
@int test(int a,int b){
int c;
c=a*b;
return c;
}void MainWindow::on_pushButton_clicked() {
int aa=4;
int bb=0;
int cc=0;
cc=test(aa,bb); } @ -
Your example looks ok.
I would declare test() as part of MainWindow but in general it looks ok.
What is wrong with your code now? -
I get this error :
S:\C&C++ programing\QT\MASTER\MASTER-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug..\MASTER\mainwindow.cpp:160: ошибка: 'test' was not declared in this scope -
Is function test() defined in mainwindow.cpp?
Is it defined before first use?If not then you need to declare it before first use.
- mainwindow.cpp
@
int test(int, int); // <-- this is a declaration
void MainWindow::on_pushButton_clicked()
{
int aa=4;
int bb=0;
int cc=0;
cc=test(aa,bb);
}int test(int a,int b)
{
int c;
c=a*b;
return c;
}
@ - mainwindow.cpp
-
Thank you this was my problem. :)