A.h頭文件中代碼:
namespace a
{void 輸出();
};
A.cpp源文件中代碼:
#include <iostream>
#include "A.h"
void a::輸出()
{std::cout << "A.h里的輸出函數" << std::endl;
}
B.h頭文件中代碼:
namespace b
{void 輸出();
};
B.cpp源文件中代碼:
#include <iostream>
#include "B.h"
void b::輸出()
{std::cout << "B.h里的輸出函數" << std::endl;
}
主函數所在源文件代碼1:引入命名空間 b
#include <iostream>
#include "A.h"
#include "B.h"
using namespace b;
int main()
{輸出();
}
運行結果 :?B.h里的輸出函數
?主函數所在源文件代碼2:引入命名空間 a
#include <iostream>
#include "A.h"
#include "B.h"
using namespace a;
int main()
{輸出();
}
運行結果 : A.h里的輸出函數
??主函數所在源文件代碼3:不引入命名空間,使用空間名字直接調用函數
#include <iostream>
#include "A.h"
#include "B.h"
int main()
{a::輸出();
}
運行結果 : A.h里的輸出函數