0

I've included two libraries to my code, both have functions called "getch", both funcions have no arguments, both return void. How to force program to choose "getch" from library A rather than B?

hooman
  • 11
  • 2
  • If you control the source code for the libraries, put the two functions in different namespaces. – Chris Apr 24 '17 at 21:52
  • That depends, can you see the declarations, and are they already in namespaces, if not you could put them in. And if you for some reason can't, you can always consult the documentation for both libraries :-) – George Apr 24 '17 at 21:54
  • You aren't including two versions of the standard library or runtime library are you? – Captain Obvlious Apr 24 '17 at 22:17

1 Answers1

3

You can't.
This is why namespaces are invented, so that you can qualify their names with their enclosing 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();
Passer By
  • 19,325
  • 6
  • 49
  • 96