0

我在参考参数方面遇到问题。中的值getStockInfo应该存储在参考参数中。我不知道该怎么做,所以displayStatus接受这些作为参数。每当我将某些东西放入getStockInfomain 中时,它都会给我错误More than one onstance of overloaded function "getStockInfo" matches the argument list

#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)
{
}  
4

2 回答 2

1

您的声明和定义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)

注意拥有多个版本并不是“错误的”。但是以编译器不知道要调用哪一个的方式调用一个。

于 2013-04-02T03:16:36.083 回答
0

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

void displayStatus(int &, double &);

对比

void displayStatus(int &backOrder, double &subtotal, double &shipping, double &total)
{
}  
于 2013-04-02T03:17:37.057 回答