C++不存在从"Date"到"Date (*)()"的合适转换函数
C++ no suitable conversion function from "Date" to "Date (*)()" exists
我正在处理一个工资单程序,但我一直在犯一个错误:
严重性代码描述项目文件行禁止显示状态错误(活动)不存在从"日期"到"日期(*)()"的合适转换函数Payroll c:\Users\Bart\Documents\Visual Studio 2015\Projects\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;
正如Eissa N.所说,编译器认为您正试图将类型为Date
的对象作为函数指针Date(*)()
传递。
从createEmployee
函数定义(和声明)中的Date date()
中删除()
。
另一种解决方案是修复createEmployee
定义以接受Date (*date)(month, day, year)
函数指针,并在createEmployee
函数中将函数createDate
传递给它,并将参数传递给它。(您必须将createDate定义为一个函数)
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 使用 std::chrono / date::gps_clock 将双 GPS 时间戳转换为 UTC/tai
- 查找字符串中的 **date** 并将其转换为其数字形式
- C++不存在从"Date"到"Date (*)()"的合适转换函数
- 将2003年8月17日转换为boost::gregori::date
- 如何将std::字符串转换为boost::gregori::date
- 将日期std::字符串转换为QuantLib::date对象
- 如何将boost::date_time::date::day_of_week()转换为字符串类型
- 如何将boost::gregorian::date转换为mm/dd/yyyy格式,反之亦然
- 将Date转换为const char*