Thread: No matching function? [C++ Error]

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    3

    No matching function? [C++ Error]

    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!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    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

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    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;
    }
    */

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    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

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    Quote Originally Posted by jimblumberg View Post
    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
    Thank you very much!

    Now it works!

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I would rather see you use std::vector or std::array.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sort: Error No matching function
    By hqt in forum C++ Programming
    Replies: 12
    Last Post: 01-03-2012, 06:47 AM
  2. Replies: 8
    Last Post: 07-08-2011, 01:16 PM
  3. No Matching Function Call for Constructor
    By manasij7479 in forum C++ Programming
    Replies: 5
    Last Post: 02-07-2011, 03:29 PM
  4. No Matching Function Error When Opening File
    By zephyrcat in forum C++ Programming
    Replies: 19
    Last Post: 07-15-2008, 01:36 PM
  5. no matching function for call to
    By f6ff in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2006, 03:34 PM