|
From: Thomas T. <tho...@ya...> - 2006-03-16 16:36:05
|
Joseph McCay wrote:
> > But based on your error messages, I'll bet you've
> > mistakenly done
> > something analogous to one of the following:
> >
> > Either:
> >
> > namespace ptl { #include <map> // erroneously
> > // imports std::map into namespace ptl
> > }
> >
> > or
> >
> > namespace ptl { using namespace std; // screws up
> > // gcc's look-up rules.
> > }
>
> My most recent problem was I using the wrong header
> name which was an
> older version. I code I gave you compiles fine when
> I use the right
> header. The older version had both of those things
> you listed. What is
> wrong with both of them? Are they legal c++?
You should ask this question on comp.c++.moderated,
where you can get a definitive answer. My
understanding, though, is:
namespace ptl {
#include map
}
causes undefined behavior, because the C++ Standard
Library must be defined in namespace ::std (which is
different from namespace ptl::std).
On the other hand, I'm not sure whether:
namespace ptl { using namespace std; }
is legal or not. It seems to cause look-up problems
for gcc, in my experience, but I don't know whether
that's because it's undefined behavior or just a bug
in gcc.
The correct way to do it is as follows:
#include <map>
namespace ptl {
using std::map;
// Your code here
}
or, if you have to (and you usually don't):
#include <map>
using namespace std;
namespace ptl {
// Your code here
}
Best regards,
Tom
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|