I've some problems to use pointers in C++. I implemented three methods with different sized arrays but the same calculations. So I decided to extract the calculations and place them in a new method which expects an array. But that doesn't work and I don't know how to modify my program.
void method1() {
float a[3][3];
calculate(a, 3);
}
void method2() {
float a[4][4];
calculate(a, 4);
}
void method3() {
float a[5][5];
calculate(a, 5);
}
void calculate(float *param[], int n) {
// Code
}
I know that I can use global variables or vectors etc. but I need the logic in this structure.
Here's the compiler error:
Test.cpp: In function 'void method1()':
Test.cpp:7:16: error: cannot convert 'float (*)[3]' to 'float**' for argument '1' to 'void calculate(float**, int)'
Test.cpp: In function 'void method2()':
Test.cpp:12:16: error: cannot convert 'float (*)[4]' to 'float**' for argument '1' to 'void calculate(float**, int)'
Test.cpp: In function 'void method3()':
Test.cpp:17:16: error: cannot convert 'float (*)[5]' to 'float**' for argument '1' to 'void calculate(float**, int)'
Thanks in advance!