I have the below code
#include<iostream>
namespace first{
void test()
{
std::cout<<"This is the first one \n";
}
}
namespace second{
void test()
{
std::cout<<"This is the second one \n ";
}
}
int main()
{
using namespace first;
test();
using namespace second;
test();
return 0;
}
The above code gives me compilation error of calling of overloaded function test.
My doubt why cannot the second using statement using namespace second hides the first namespace?
Next I tried declaring the namespace inside a function body, this may sound strange but i tried to check whether i can do that or not, It also resulted in the compilation error. Which makes me wonder is it only at the global scope that I can declare the namespaces?
My third and last question is, is there any way by which I can only declare the two function with the same signature inside two different namespaces and the define them outside the outside the namespace block? Like below
#include<iostream>
namespace first{
void test();
}
namespace second{
void test();
}
int main()
{
return 0;
}
Again idk whether my question is valid or not.