2013-04-02 3 views
0

참조 매개 변수에 문제가 있습니다. getStockInfo의 값은 참조 매개 변수에 저장되어 있습니다. 그걸 어떻게 해야할지 모르겠다. 그래서 displayStatus을 인자로 받아 들인다. 내가 메인에 getStockInfo에 뭔가를 집어 넣을 때마다 나는 에러 More than one onstance of overloaded function "getStockInfo" matches the argument list을 준다.C++ 참조 매개 변수 함수

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

코드에서 getStockInfo' '의 두 곳을보고 비교 대. – chris

+1

함수 프로토 타입, 둘 다 및 실제 정의를 살펴보십시오. 그들은 평등하지 않습니다. –

답변

1

내 선언 getStockInfo의 정의는 상이 하나에서 최종 파라미터를 참조하고 기타의 것이 아니다.

void getStockInfo(int &, int&, double&); 
... 
void getStockInfo(int &spoolsOrdered, int &spoolsStock, double specialCharges) 

유사한 문제가 발생 displayStatus : 여기 파라미터의 개수가 다르다. 컴파일러는 당신이 getStockInfo(int &, int&, double&) 전화를 말하는 여부를 확인할 수 없기 때문에

void displayStatus(int &, double &); 
... 
void displayStatus(int &backOrder, double &subtotal, double &shipping, double &total) 

오류 메시지가 발생합니다 (다른 파일에서 올 수 있음) 또는이 파일 void getStockInfo(int &, int&, double)에 정의 된 하나.

여러 버전을 사용하는 것은 "잘못"되지 않습니다. 그러나 컴파일러가 호출 할 수있는 방법을 알지 못하는 방식으로 호출합니다.

0

프로토 타입의 매개 변수 목록이 정의에있는 매개 변수 목록과 일치하지 않습니다.

void displayStatus(int &, double &); 

void displayStatus(int &backOrder, double &subtotal, double &shipping, double &total) 
{ 
}