我在将void (*)()
转换为float
时遇到问题。这是我的代码:
#include <iostream>
using namespace std;
void instructions();
void numDays();
void med();
void sur();
void lab();
float room(int days);
float misc(float meds, float surgical, float lab);
float total(float room, float misc);
int main()
{
int days;
float meds;
float surgical;
instructions();
numDays();
med();
sur();
lab();
room( days);
misc(meds, surgical, lab);
total( room, misc);
}
void instructions()
{
cout<<"this program will ask you some questions. After that it will print out all of the users charges and the tital\
amount that is owed. "<<endl;
}
void numDays()
{
float days;
cout<<"Enter in users length of stay. "<<endl;
cin>> days;
}
void med()
{
float meds;
cout<<"Enter int the users medication charges. "<<endl;
cin>> meds;
}
void sur()
{
float surgical;
cout<<"Enter in the users surgical charges. "<<endl;
cin>> surgical;
}
void lab()
{
float lab;
cout<<"Enter in the users lab fees. "<<endl;
cin>> lab;
}
float room(float days)
{
float room;
room = (days*450);
}
float misc(float meds, float surgical, float lab)
{
float misc;
misc = (meds + surgical + lab);
return 0;
}
float total(float room, float misc)
{
float total;
total = (room + misc);
return total;
}
这些是我不断收到的错误消息:
:24: error: cannot convert 'void (*)()' to 'float' for argument `3' to `float misc(float, float, float)'
:25: error: cannot convert 'float (*)(int)' to 'float' for argument `1' to `float total(float, float)'
最佳答案
例如在此语句中
misc(meds, surgical, lab);
参数实验室是一个函数指针。我没有看过您的代码,但也许您的意思是
misc(meds, surgical, lab());
但是,即使在这种情况下,由于函数lab的返回类型为void,您也会收到错误消息。
看来您不了解自己在做什么。
关于c++ - 错误: cannot convert `void (*)()' to `float' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19779344/