强制选择其他功能

时间:2017-04-24 21:45:59

标签: c++

我在我的代码中包含了两个库,它们都有名为" getch"的函数,两个函数都没有参数,都返回void。如何强制程序选择" getch"从图书馆A而不是B?

1 个答案:

答案 0 :(得分:3)

你不能。
这就是namespace被发明的原因,因此您可以使用封闭的namespace限定其姓名。

//These modifications have to be made in the library source files
namespace A { void getch(); }
namespace B { void getch(); }

//When you want to use them
A::getch();
B::getch();