Opps small typo in the second one. Should have been:
Code:
mynamespace::cout<<"Hello world"<<mynamespace::endl;
To show you exactly what happens lets take the following program:
Code:
#include <iostream>
//#define cout std::cout
namespace mynamespace
{
std::ostream& endl (std::ostream& o)
{
return o<<'\n'<<std::flush;
}
std::ostream& cout = std::cout;
};
int main()
{
std::cout<<"Hello world"<<std::endl;
mynamespace::cout<<"Hello world"<<mynamespace::endl;
}
This compiles and produces the expected results.
Nows lets comment the #include and uncomment the #define and tell gcc to do only the preprocesser work. Now our program looks like this:
Code:
namespace mynamespace
{
std::ostream& endl (std::ostream& o)
{
return o<<'\n'<<std::flush;
}
std::ostream& std::cout = std::std::cout;
};
int main()
{
std::std::cout<<"Hello world"<<std::endl;
mynamespace::std::cout<<"Hello world"<<mynamespace::endl;
}
See the problem now?