Re: #include within namespace scope
On Feb 16, 10:18 am, joec...@gmail.com wrote:
On Feb 16, 9:10 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
joec...@gmail.com writes:
Is there anything that prevents putting #include directives inside
namespace scope within the standard?
Nothing, but you will declare the stuff defined in the header inside
this namespace.
Let's say I have a (evil) header:
Therefore you have:
namespace evil
{
#include <vector>
using namespace std; // bad doggy
class Doo
{
public:
vector<int> d;
};
}
int main()
{
// Nothing
}
That is, you are using a class evil::std::vector<int>
Where is the implementation of this class?
Notice that libg++ only defines methods such as std::vector<int>::clear=
,
not evil::std::vector<int>::clear.
I expected the preprocessor to expand the include header at the
location I have put it.
I further expected that the compiler should always refer to ::std::
instead of std::, and therefore 'std' will not get caught inside the
namespace where it is not intended. Somewhere that expectation is
being broken, and I'm still not sure exactly where..
Joe C- Hide quoted text -
- Show quoted text -
To clarify,
The standard states, "Whenever a name x defined in the standard
library is mentioned, the name x is assumed to be fully qualified
as ::std::x, unless explicitly described otherwise. For example, if
the Effects section for library function F is described as calling
library function G, the function ::std::G is meant."
In this case, the compiler seems to be making the assumption that
include directives will always be at global scope, but I cannot find
any part of the standard that would back up such an assumption. That
is what I am searching for.
Thanks!
Joe C