c++ - 错误: cannot convert `void (*)()' to `float'

标签 c++ function compiler-errors syntax-error

我在将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/

相关文章:

c++ - 如何在 C++17 中制作模板包装器/装饰器

c++ - 只初始化只读数组一次

c++ - 通过凹多边形计算位置聚类中心约束的最快方法是什么

php - PHP 中每个文件只有一个或多个函数?

javascript - 错误:xwalk_autofill_client.cc(121) 未在虚拟无效 xwalk::XWalkAutofillClient::OnFirstUserGestureObserved() 中实现

maven - 如何将 Spring Boot 构建插件与 JavaFX 应用程序一起使用

java - 使用 JNI 从 Java 调用 C++ 程序时出错。获取 SEGV_ACCERR

c++ - 设置窗口几何属性的正确方法

c - 第一次将CS50 IDE用于问题集2时的错误消息-可读性

聚光灯后 jQuery 重置回 css