namespace A
{
#include <iostream>
};
int main(){
A::std::cout << "\nSample";
return 0;
}
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Short answer: No.
Long answer: Well, not really. You can fake it, though. You can declare it outside and use using statements inside the namespace, like this:
You cannot localize a library, because even if it had access in A, it would not have access in the standard namespace.
Also, "The other problem is that the qualified names inside the namespace would be A::std::cout, but the library would not contain names qualified with the outer namespace." thanks Jonathon Leffler.
If the problem is that you don't want to let other people know what all your code can do, you could have your own cpp file to include iostream in, and have the namespace defined there. Then you just include that in main (or whatever) and let the programmer know what he can and cannot do.
You could write:
Thit approach is called namespace aliasing. Real purpose for that feature showed in the following sample: