A.h头文件中代码:
cpp
namespace a
{
void 输出();
};
A.cpp源文件中代码:
cpp
#include <iostream>
#include "A.h"
void a::输出()
{
std::cout << "A.h里的输出函数" << std::endl;
}
B.h头文件中代码:
cpp
namespace b
{
void 输出();
};
B.cpp源文件中代码:
cpp
#include <iostream>
#include "B.h"
void b::输出()
{
std::cout << "B.h里的输出函数" << std::endl;
}
主函数所在源文件代码1:引入命名空间 b
cpp
#include <iostream>
#include "A.h"
#include "B.h"
using namespace b;
int main()
{
输出();
}
运行结果 : B.h里的输出函数
主函数所在源文件代码2:引入命名空间 a
cpp
#include <iostream>
#include "A.h"
#include "B.h"
using namespace a;
int main()
{
输出();
}
运行结果 : A.h里的输出函数
主函数所在源文件代码3:不引入命名空间,使用空间名字直接调用函数
cpp
#include <iostream>
#include "A.h"
#include "B.h"
int main()
{
a::输出();
}
运行结果 : A.h里的输出函数