我之前問過關於此程序的問題,但仍有疑問。我在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中定義的錯誤。
「mStatus,nOfChildren,salary,contribPension'聲明在哪裏? –
當我在名稱空間中聲明它們時,它提供了一個錯誤,指出它們已經在stdfax中定義。當我嘗試在main中聲明它時,它也會給出同樣的錯誤。 – user3273096
我會從stdfax.h中刪除命名空間。該文件保留用於VS中的預編譯頭文件。把它放在它自己的頭文件中(「deductions.h」),並將其包含在主文件中。清理並重建您的項目。 –