I am using the <conio.h> header file, and somewhere else in my source code I define a function with the name getch and it has to have that name. Since there already is a getch in <conio.h>, and this header file declares all of its functions in the global namespace, I get a name collision.
I found that using the following syntax would avoid the collision:
namespace some_namespace
{
#include <conio.h>
}
Then I can use some_namespace::getch when I want to access the function in <conio.h> and getch when I want to access my own function.
Is this valid syntax? I know <conio.h> is only for windows, but is this kind of syntax going to behave the same across all the compilers? What other ways do you suggest to get around this problem?
Edit:
I use GCC and MSVC 2019 on Windows and it compiles fine on both of them.
I can access the functions in <conio.h> as well, getch in particular as I showed above (even though I should use the name _getch instead of getch in MSVC).