C++ c++;参考参数函数

C++ c++;参考参数函数,c++,function,parameters,reference,C++,Function,Parameters,Reference,我在参考参数方面有问题。getStockInfo中的值应该存储在参考参数中。我不知道如何才能让displaystation接受这些参数。每当我在main中将某个内容放入getStockInfo时,它都会给出一个错误多个重载函数的实例“getStockInfo”与参数列表匹配 #include <iostream> #include <iomanip> using namespace std; void getStockInfo(int &, int&,

我在参考参数方面有问题。
getStockInfo
中的值应该存储在参考参数中。我不知道如何才能让
displaystation
接受这些参数。每当我在main中将某个内容放入
getStockInfo
时,它都会给出一个错误
多个重载函数的实例“getStockInfo”与参数列表匹配

#include <iostream>
#include <iomanip>
using namespace std;

void getStockInfo(int &, int&, double&);
void displayStatus(int &, double &);

int main()
{
   int spoolsOrdered;
   int spoolsStock;
   double specialCharges;

   cout << "Middletown Wholesale Copper Wire Company" << endl;

   getStockInfo(spoolsOrdered, spoolsStock, specialCharges);
}

void getStockInfo(int &spoolsOrdered, int &spoolsStock, double specialCharges)
{
   char ship; 

   cout << "How many spools would you like to order: ";
   cin >> spoolsOrdered;

   //Validate the spools ordered 
   while(spoolsOrdered < 1)
   {
      cout << "Spools ordered must be at least one" << endl;
      cin >> spoolsOrdered;
   }

   cout << "How many spools are in stock: ";
   cin >> spoolsStock;

   //Validate spools in stock
   while(spoolsStock < 0)
   {
       cout << "Spools in stock must be at least 0" << endl;
       cin >> spoolsStock;
   }

   cout << "Are there any special shipping charges? ";
   cout << "Enter Y for yes or another letter for no: ";
   cin >> ship;

   //Validate special charges
   if(ship == 'Y' || ship == 'y')
   {
    cout << "Enter the special shipping charge: $";
    cin >> specialCharges;
   }
   else
   {
    specialCharges = 10.00;
   }
}

void displayStatus(int &backOrder, double &subtotal, double &shipping, double &total)
{
}  
#包括
#包括
使用名称空间std;
void getStockInfo(int&,int&,double&);
无效显示状态(整数和,双精度和);
int main()
{
整编;
国际短管库存;
双重特殊收费;
cout-spoolsStock;
//验证库存的线轴
同时(滑阀总成<0)
{
cout-spoolsStock;
}
不能装运;
//确认特殊费用
if(ship='Y'| | ship='Y')
{
特殊费用;
}
其他的
{
特殊费用=10.00;
}
}
无效显示状态(整数和延期订单、双倍和小计、双倍和装运、双倍和总计)
{
}  

您对
getStockInfo
的声明和定义有所不同:一个中的最后一个参数是引用,另一个中不是引用

void getStockInfo(int &, int&, double&);
...
void getStockInfo(int &spoolsOrdered, int &spoolsStock, double specialCharges)
displayStatus
也会出现类似问题:这里的参数数量不同

void displayStatus(int &, double &);
...
void displayStatus(int &backOrder, double &subtotal, double &shipping, double &total)
由于编译器无法确定是让它调用
getStockInfo(int&,int&,double&)
(可能来自另一个文件)还是调用此文件中定义的
void getStockInfo(int&,int&,double)
,因此会出现错误消息


注:具有多个版本并非“错误”。但是,以编译器不知道调用哪一个的方式调用它。

原型中的参数列表与定义中的参数列表不匹配

void displayStatus(int &, double &);
vs


查看代码中
getStockInfo
的两个位置并进行比较。查看函数原型,两个原型,以及实际的定义。他们不平等。
void displayStatus(int &backOrder, double &subtotal, double &shipping, double &total)
{
}