C++ 如何在重载函数中包含和重载函数
这是我的完整代码。如果病例为一(1)例,我尝试将住院患者包括在内,但一些突出显示表明这是错误的。如果没有,有什么方法可以解决这个问题吗?如果输入了一(1),请告诉我另一种方法,只要它包括住院患者C++ 如何在重载函数中包含和重载函数,c++,C++,这是我的完整代码。如果病例为一(1)例,我尝试将住院患者包括在内,但一些突出显示表明这是错误的。如果没有,有什么方法可以解决这个问题吗?如果输入了一(1),请告诉我另一种方法,只要它包括住院患者 void selection(int &); void processor(int &); void inPatient(double &, double &, double &, double &); int main() { int sele
void selection(int &);
void processor(int &);
void inPatient(double &, double &, double &, double &);
int main()
{
int selected, include;
double numberOfDays, dailyRate, chargesForHospital, hospitalMedicationCharge;
selection(selected);
validate(selected, selected);
processor(selected);
system("pause");
return(0);
}
void selection(int & selectedOption)
{
cout << "\nEnter Selection: ";
cin >> selectedOption;
}
void processor(int & selectedOption)
{
switch(selectedOption)
{
case 1:
inPatient(umberOfDays, dailyRate, chargesForHospital, hospitalMedicationCharge);
break;
case 2:
cout << "out-Pat" << endl;
break;
default :
cout << "Nothing Selected" << endl;
break;
}
}
void inPatient(double & numberOfDays, double & dailyRate, double & chargesForHospital, double & hospitalMedicationCharge)
{
cout << "The number of days spent in the hospital: ";
cin >> numberOfDays;
cout << "The daily rate: ";
cin >> dailyRate;
cout << "Charges for hospital services (lab tests, etc.): ";
cin >> chargesForHospital;
cout << "Hospital medication charges: ";
cin >> hospitalMedicationCharge;
}
无效选择(int&);
无效处理器(int&);
无效住院病人(双&,双&,双&,双&);
int main()
{
选择int,包括;
双倍天数,每日一次,药费,住院药费;
选择(已选择);
验证(选中,选中);
处理器(选定);
系统(“暂停”);
返回(0);
}
无效选择(int和selectedOption)
{
cout>selectedOption;
}
无效处理器(int和selectedOption)
{
开关(选择选项)
{
案例1:
住院患者(天数、日住院天数、住院费、住院药费);
打破
案例2:
不能收取住院药费;
}
您发布的代码中有许多错误,但我将尝试解决您眼前的问题。您正在尝试调用如下函数:
patric(int & gender, int & age)
patric(someGender, someAge);
但这更像是一个函数声明。要真正调用函数,请传入参数,但忽略类型,如下所示:
patric(int & gender, int & age)
patric(someGender, someAge);
声明中的int&
表示参数是对int
类型值的引用,因此调用patric
时传递的值应该是int
类型
另外,您还说,patric
被重载了。这意味着函数有多个版本,每个版本都有不同的参数列表。因此,可能有上面的版本,也有一个不带任何值的版本——可能它们的声明分别如下所示:
void patric(int &gender, int &age);
void patric(void);
鉴于此,如果您想调用第二个版本,您只需调用它:
patric();
(第二个版本中参数列表中的void
表示函数不接受任何参数。函数名称前的void
表示函数不返回任何参数。)
还要注意,您需要一个分号(
;
)在函数调用之后。将patric包含到名称中的正确方法是什么?这里有很多错误,请发布一些实际编译的代码。您确定知道重载函数的含义吗?因为在您的示例中没有重载,尽管它们可能在其他地方。在您的新代码中也没有重载。我该如何确定我是谁不要说案例1:“住院病人…”工作?你能再看一遍吗?