Another beginner question...
The following compiles and runs without any problem:
Code:
#include <iostream>
using namespace std;
namespace ns1
{
char *string1 = "string 1 ns1";
char *string2 = "string 2 ns1";
}
namespace ns2
{
char *string1 = "string 1 ns2";
char *string2 = "string 2 ns2";
}
namespace comb1
{
using namespace ns1;
using namespace ns2;
using ns1::string1;
using ns2::string2;
}
int main()
{
cout << comb1::string1 << ", " <<comb1::string2 << endl;
return 0;
}
However, if I change the first line in main() to:
Code:
using namespace comb1;
cout << string1 << ", " << string2 << endl;
the compiler gets confused by the conflicting definitions of string1 and string2 and gives an error. I can't see why there should be any difference between the two versions.
Any suggestions?