关于名称空间的问题
源代码如下
//345.h
namespace pers
{
const int LEN=40;
struct Person
{
char fname[LEN];
char lname[LEN];
};
void getPerson(Person &);
void showPerson(const Person &);
}
namespace debts
{
using namespace pers;
struct Debt
{
Person name;
double amount;
};
void getDebt(Debt &);
void showDebt(const Debt &);
double sumdebts(const Debt ar[],int n);
}
#include <iostream>
//#include <string>
using namespace std;
#include "345.h"
namespace pers
{
void getPerson(Person &rp)
{
cout<<"Enter first name: ";
cin>>rp.fname;
cout<<"Enter last name: ";
cin>>rp.lname;
}
void showPerson(const Person &rp)
{
cout<<rp.lname<<","<<rp.fname;
}
}
namespace debts
{
void getDebt(Debt &rd)
{
err: getPerson(rd.name);
cout<<"Enter debt: ";
cin>>rd.amount;
}
void showDebt(const Debt &rd)
{
err: showPerson(rd.name);
cout<<": $"<<rd.amount<<endl;
}
double sumDebts(const Debt ar[],int n)
{
double total=0;
for(int i=0;i<n;i++)
total=+ar[i].amount;
return total;
}
}
#include <iostream>
using namespace std;
#include "345.h"
void other(void);
void another(void);
int main(void)
{
using debts::Debt;
using debts::showDebt;
Debt golf={{"Benny","Goatsniff"},120.0};
showDebt(golf);
other();
another();
return 0;
}
void other(void)
{
using namespace debts;
Person dg={"Doodles","Glister"};
showPerson(dg);
cout<<endl;
err: Debt zippy[3];
int i;
for(i=0;i<3;i++)
getDebt(zipppy[i]);
for(i=0;i<3;i__)
showDebt(zippy[i]);
err: cout<<"Total debt: $"<<sumDebts(zippy,3)<<endl;
return;
}
void another(void)
{
using pers::Person;;
Person collector={"Milo","Rightshift"};
pers::showPerson(collector);
cout<<endl;
}
compile是提示getPerson()和showPerson()未定义;