简体   繁体   English

C ++不存在从“日期”到“日期(*)()”的合适转换函数

[英]C++ no suitable conversion function from “Date” to “Date (*)()” exists

I'm working on a payroll program but I keep stumbling on this one error: 我正在开发一个工资核算程序,但是我一直绊在这个错误上:

Severity Code Description Project File Line Suppression State Error (active) no suitable conversion function from "Date" to "Date (*)()" exists Payroll c:\\Users\\Bart\\Documents\\Visual Studio 2015\\Projects\\Payroll\\Payroll\\Payroll.cpp 58 严重性代码说明项目文件行抑制状态错误(活动)不存在从“日期”到“日期(*)()”的合适转换功能工资单c:\\ Users \\ Bart \\ Documents \\ Visual Studio 2015 \\ Projects \\ Payroll \\ Payroll \\ Payroll.cpp 58

Here's my main: 这是我的主要资料:

int main()
{
int count = 0;
int option = 0;
int month;
int day;
int year;

cout << fixed << setprecision(2);

Employee *employees[arraySize];

cout << "Welcome to the payroll program!" << endl;

cout << "Please enter the current month: ";
cin >> month;

cout << "Please enter the current day: ";
cin >> day;

cout << "Please enter the current month: ";
cin >> year;

Date currentDate(month, day, year);

while (option != 3)
{
    cout << endl << "Please select one of the following options" << endl;
    cout << "1 - Enter new employee information" << endl;
    cout << "2 - View payroll" << endl;
    cout << "3 - Exit the application" << endl;
    cout << "Please enter your option: ";
    cin >> option;

    switch (option)
    {
        case 1:
            if (count < arraySize)
                {
                    count+= createEmployee(employees, count, currentDate);
                    //This is where the error is occurring, currentDate is underlined
                }
            else
            {
                cout << "You cannot enter any more than " << arraySize << " employees." << endl;
            }
                break;
        case 2:
            displayEmployees(employees, count);
            break;
        case 3:
            break;
        default:
            cout << "Please enter a valid menu selection";
    }
}
return 0;
}

And here is the first part of my createEmployee method: 这是我的createEmployee方法的第一部分:

int createEmployee(Employee *employees[], int index, Date date())
{
string firstName;
string middleName;
string lastName;
int bDay;
int bMonth;
int bYear;
Date currentDate = date();
string SSN;
int option;

As Eissa N. says, compiler thinks you are trying to pass object of type Date as a function pointer Date(*)() . 正如Eissa N.所说,编译器认为您试图将Date类型的对象作为函数指针Date(*)()传递。

Remove the () from Date date() in createEmployee function definition (and declaration). createEmployee函数定义(和声明)中的Date date()中删除() )。

Other solution would be to fix the createEmployee definition to accept Date (*date)(month, day, year) function pointer and pass function createDate to it and pass arguments to it in createEmployee function. 其他解决方案是修复createEmployee定义,以接受Date (*date)(month, day, year)函数指针,并将函数createDate传递给它,并在createEmployee函数中传递参数给它。 (you would have to define createDate a function) (您必须定义createDate函数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM