hello all,
could someone tell me why this code does not work?
The link: Pastebin
The error is:
17|error: no matching function for call to 'AddizionaFrazioni(int (*)[2][2], int)'|
Thanks!
This is a discussion on No matching function? [C++ Error] within the C++ Programming forums, part of the General Programming Boards category; hello all, could someone tell me why this code does not work? The link: Pastebin The error is: 17|error: no ...
hello all,
could someone tell me why this code does not work?
The link: Pastebin
The error is:
17|error: no matching function for call to 'AddizionaFrazioni(int (*)[2][2], int)'|
Thanks!
Does the AddizonaFrazion() function exist? If so does this function have the same number and type of arguments? Check the spelling and remember that C++ is case sensitive. Otherwise post your code between code tags.
Jim
Yes, the function exists..
This is the code:
Code:#include <iostream> using namespace std; template <class type> type mcm(type*,type); template <class type> type MinInArr(type*,type); // template <class type> type MaxInArr(type*,type); template <class type> type* AddizionaFrazioni(type**,type); int main() { cout << "Start.." << endl; int frazioni[2][2] = { {1,4}, {2,4} }; int *risultato; risultato = AddizionaFrazioni(&frazioni,2); cout << risultato[0] << "%" << risultato[1] << endl; return 0; } template <class type> type* AddizionaFrazioni(type** frazioni, type nfrazioni) { type denominatore = 0; type *denominatori = new type[nfrazioni]; type numeratore = 0; for(type i = 0; i < nfrazioni; i++) { denominatori[i] = frazioni[i][0]; } denominatore = mcm(denominatori,nfrazioni); delete [] denominatori; for(int i = 0; i < nfrazioni; i++) { numeratore += denominatore/frazioni[i][1]*frazioni[i][0]; } type risultato = new type[2]; risultato[0] = numeratore; risultato[1] = denominatore; return risultato; } template <class type> type mcm(type *numeri, type len) { type mcm = MinInArr(numeri,len); type i = 0, err = 0; while(1) { err = 0; for(i = 0; i < len; ++i) { if( (mcm % numeri[i]) != 0 ) { ++err; break; } } if (err == 0) { return mcm; } ++mcm; } } template <class type> type MinInArr(type *numeri, type len) { type min = NULL; for(type i = 0; i < len; ++i) { if( (min == NULL) || (min > numeri[i]) ) { min = numeri[i]; } } return min; } /* template <class type> type MaxInArr(type *numeri, type len) { type max = NULL; for(type i = 0; i < len; ++i) { if( (max == NULL) || (max < numeri[i]) ) { max = numeri[i]; } } return max; } */
Okay the function exists but you are not calling it with the proper parameters. Your variable frazioni[2][2] only has two dimensions, in the function call you are trying to send a int (*)[2][2] (three dimensions). Remember the address of an array is the array name, you don't want to use the ampersand when calling this function.
Jim