没有匹配的函数调用 - Xcode?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26154369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:45:49  来源:igfitidea点击:

no matching function for call to - Xcode?

c++xcode

提问by Codetographer

Everything seems to check out in my code; I've checked syntax on the different functions and everything seems to be checking out but I still seem to be getting the error 'No Matching Function for Call to 'MyInput'' in XCode with no explanation. Any help would be appreciated! Code follows.

一切似乎都在我的代码中检查出来;我已经检查了不同函数的语法,一切似乎都在检查,但我似乎仍然在 XCode 中收到错误“没有匹配函数调用‘MyInput’”,没有任何解释。任何帮助,将不胜感激!代码如下。

#include <iostream>
#include <iomanip> 
using namespace std;

typedef char ShortName[10];
typedef char LongName[17];
typedef char IDarray[6];

void MyInput(ShortName [],char [], LongName [], float [],int [],IDarray [],int&);



int main(int argc, const char * argv[])
{
    const int max = 7;
    const int ConstStateTax = .05;
    const int ConstFedTax = .15;
    const int ConstUnionFees = .02;
    ShortName firstname[max];
    char MI[max];
    LongName lastname[max];
    float hourrate[max];
    int OTHours[max];
    float Gross[max];
    float Overtime[max];
    float GGross[max];
    float StateTax[max];
    float FedTax[max];
    float UnionFees[max];
    IDarray EmployeeID[max];
    float Net[max];

    MyInput(firstname,MI,lastname,hourrate,OTHours,EmployeeID,max);


    return 0;
}

void MyInput(ShortName firstname[],char MI[],LongName lastname[],float hourrate[],int OTHours[],IDarray EmployeeID[],int &max)
{
    for(int i = 0;i<=max;i++)
    {
        cout << "Please enter the first name of employee #" << i+1 << ": ";
        cin >> firstname[i];
        cout << "Please enter the middle initial of employee #" << i+1 << ": ";
        cin >> MI[i];
        cout << "Please enter the last name of Employee #" << i+1 << ": ";
        cin >> lastname[i];
        cout << "What is the ID number of Employee #" << i+1 << "? (6 letters or numbers only): ";
        cin >> EmployeeID[i];
        cout << "What is the hourly rate of employee #" << i+1 << "? ";
        cin >> hourrate[i];
        while (hourrate[i] < 0)
        {
            cout << "Invalid rate, please try again: ";
            cin >> hourrate[i];
        }
        cout << "How many overtime hours does employee #" << i+1 << " have? ";
        cin >> OTHours[i];
        while(OTHours[i]<0 || OTHours[i] >20)
        {
            cout << "Invalid Overtime Hours, please re-enter: ";
            cin >> OTHours[i];
        }
    }


}

回答by Bryan Chen

the function you are trying to call is, which takes int&as last argument

您尝试调用的函数是,它int&作为最后一个参数

void MyInput(ShortName [],char [], LongName [], float [],int [],IDarray [],int&);

but you pass const int maxto it, which have type of const intand can't convert to int&

但是你传递const int max给它,它有类型const int并且不能转换为int&

to fix it, change int&to intfor both method declaration and definition

要解决这个问题,改变int&int两种方法声明和定义