Let's say instead of using the using namespace std and have the name declared regardless of the header file, is there a way to use the namespace std in only one header file, for instance the algorithm header file. Is there a way to do that.
Let's say instead of using the using namespace std and have the name declared regardless of the header file, is there a way to use the namespace std in only one header file, for instance the algorithm header file. Is there a way to do that.
I am not sure about a single library, but you can qualify each individual name you want
Code:using std::cout;
Using DEV-C++ Under Windows XP
+------------------------------+
"No! Do, or Do Not. There is no Try..."
well that I know about. I was thinking just names within the scope of a specific library.
One possible way is to enclose the header in a namespace and have the using directive inside it.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Uh, no, that won't work, and might be forbidden. Consider:
Now what happens if algorithm requires something from iterator? Well, it would first include the iterator header itself. However, due to include guards, that wouldn't have any effect. Then it would try to access an element of that header. Since it is already in the namespace std (it thinks), it would use unqualified access. Which means it tries to access e.g. std::iterator_traits with the unqualified iterator_traits from, say, mine::std::copy. Nu-uh, won't work.Code:#include <iterator> namespace mine { #include <algorithm> using namespace mine::std; }
It might actually be explicitely forbidden by the standard, but I'm not sure about that.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I used the wrong wording. I meant inside the header file... surround all or part of the code by a namespace declaration and use the directive inside that namespace.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Oh, I see.
I wouldn't do that either. VC++ 2005 has a bug with this code:
Code:#include <iostream> namespace mine { using namespace std; // ... } // All symbols from std are visible here, too.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I guess in the end it would just be easier the way it was meant to be. Just was curious though, thanks for the input.