2014-02-05 1 views
0

이 프로그램에 대해 이전에 질문을했지만 질문이 있습니다. stdfax.h 파일에서 네임 스페이스를 만들고 main에서 함수를 호출하려고합니다.네임 스페이스 - 선언 식별자에서 메서드 호출

#include "stdafx.h" 
#include <iostream> 
#include <iomanip> 

using namespace std; 

int main() 
{ 
    deductions::getData(mStatus, nOfChildren, salary, contribPension); 
    deductions::taxAmount(mStatus, nOfChildren, salary, contribPension); 
} 

네임 스페이스는 다음과 같습니다

#pragma once 

#include <iostream> 
#include <iomanip> 

using namespace std; 

namespace deductions 
{ 
    const double marriedDeduction = 7000.00; 
    const double singleDeduction = 4000.00; 
    const double personalExemption = 1500.00; 

    void getData(char& mStatus, int& nOfChildren, double& salary, 
       double& contribPension) 
    {cout << "\n\n Enter marital status: m or M (married), s or S (single): "; 
    cin >> mStatus; 

    if(mStatus == 'm' || mStatus == 'M') 
    { 
     cout << " Number of children:" << setfill(' ') << setw(40) << ' '; 
     cin >> nOfChildren; 
    } // end IF 

    cout << setfill(' '); 
    cout << " Enter gross Salary:" << setw(40) << ' '; 
    cin >> salary; 
    cout << " Percentage of salary contributed to Pension (0 to 6):" << setw(6) << ' '; 
    cin >> contribPension; 
    cout << endl;} // end getData( 

    double taxAmount(char mStatus, int nOfChildren, double salary, 
      double contribPension)  
    {...} 
}; 

오류가 메인에서 선언되지 않은 식별자입니다. 다시 말하지만, 나는 그걸 만지작 거리며 시도해 보았고 작동시키지 못했습니다. 죄송합니다 바보 같은 오류가 있다면; 나는 다른 사람의 코드와 함께 일하고 있는데, 오랫동안 그것을 더 이상 이해하지 못한다.

main에서 변수를 선언하면 stdfax에 이미 정의되어 있다는 오류가 발생합니다.

int main() 
{ 
    deductions::getData(mStatus, nOfChildren, salary, contribPension); 
    deductions::taxAmount(mStatus, nOfChildren, salary, contribPension); 
} 

당신이 그들을 선언해야합니다 :

+1

'mStatus, nOfChildren, salary, contribPension'은 어디에 선언되어 있습니까? –

+0

네임 스페이스에 선언 한 것들을 stdfax에 이미 정의했다는 오류가 발생합니다. 그것은 main에서 선언하려고 할 때도 같은 오류가 발생합니다. – user3273096

+0

stdfax.h에서 네임 스페이스를 제거합니다. 이 파일은 VS의 미리 컴파일 된 헤더 용으로 예약되어 있습니다. 그것을 자신의 헤더 ("deductions.h")에 넣고 그것을 메인에 포함시킵니다. 프로젝트를 정리하고 다시 빌드하십시오. –

답변

2

당신의 방법에 사용되는 식별자를 선언하십시오 ...

deductions::getData(mStatus, nOfChildren, salary, contribPension); 
3

당신은 당신이 매개 변수로 전달하는 변수를 선언하지 않았습니다. 예 :

int main() 
{ 
    char mStatus; 
    int nOfChildren; 
    double salary, contribPension; 
    deductions::getData(mStatus, nOfChildren, salary, contribPension); 
    deductions::taxAmount(mStatus, nOfChildren, salary, contribPension); 
} 
+1

const가 아닌 한 리터럴을 참조로 전달할 수 없습니다. –

+0

오, 그래. 그것을 잊어 버렸습니다. 함수 이름이'getData' 인 것을 고려하면, 참조는 아마도 const가되어야하고 전혀 참조가 아닐 것입니다. 정의가 없으면 말하기 어렵다. – user2079303

+0

get 데이터가'void'를 반환하기 때문에 나는 사용자로부터 데이터를 어떻게 든 얻고 그것을 입력 매개 변수에 할당한다고 가정합니다. –

관련 문제