이 프로그램에 대해 이전에 질문을했지만 질문이 있습니다. 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);
}
당신이 그들을 선언해야합니다 :
'mStatus, nOfChildren, salary, contribPension'은 어디에 선언되어 있습니까? –
네임 스페이스에 선언 한 것들을 stdfax에 이미 정의했다는 오류가 발생합니다. 그것은 main에서 선언하려고 할 때도 같은 오류가 발생합니다. – user3273096
stdfax.h에서 네임 스페이스를 제거합니다. 이 파일은 VS의 미리 컴파일 된 헤더 용으로 예약되어 있습니다. 그것을 자신의 헤더 ("deductions.h")에 넣고 그것을 메인에 포함시킵니다. 프로젝트를 정리하고 다시 빌드하십시오. –