Something like this will give a bunch of compiler errors because the functions are qualified like ::isalnum
:
namespace {
#include <iostream>
};
Is there a way to hide standard library functions in an anonymous namespace?
Something like this will give a bunch of compiler errors because the functions are qualified like ::isalnum
:
namespace {
#include <iostream>
};
Is there a way to hide standard library functions in an anonymous namespace?
Not really (at least in the usual way of implementing things).
Putting something into a namespace affects the name of that items that's created in an object file.
That means the "path" (i.e., all the namespaces to get to a name) need to be identical between the declaration and definition of an item, or else the names won't match.
If you enclose the header inside a namespace, when you try to link it'll look for names that don't exist, so linking will fail.
This is particularly true in the case of an anonymous namespace like you've used above, which means a definition is only visible inside the same translation unit. That means unless the definitions of the function(s) (etc.) in question were in that file, placing them in an anonymous namespace means they couldn't be found anyway.