我正在制定薪资计划,但我一直在绊倒这一个错误:
严重级代码描述项目文件行抑制状态 错误(活动)没有合适的转换功能从“日期”到“日期(*)()”存在工资单c:\ Users \ Bart \ Documents \ Visual Studio 2015 \ Projects \ Payroll \ Payroll \ Payroll.cpp 58
这是我的主要内容:
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;
}
这是我的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;
答案 0 :(得分:0)
正如Eissa N.所说,编译器认为您正在尝试将Date
类型的对象作为函数指针Date(*)()
传递。
从()
函数定义(和声明)中的Date date()
中删除createEmployee
。
其他解决方案是修复createEmployee
定义以接受Date (*date)(month, day, year)
函数指针并将函数createDate
传递给它并在createEmployee
函数中将参数传递给它。 (你必须定义createDate一个函数)