This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: STL headers problem


Joe Buck wrote:
> 
> > If your code doesn't mention namespaces, you'll be better off using
> > <vector.h> than using <vector> today.  That way when the new libraries
> > come out you will change a simple compiler flag to keep your code
> > working; otherwise everything breaks.
> 
> Actually, if the program says
> 
> #include <vector>
> using namespace std;
> 
> it will work before and after the conversion (since std is currently a
> "dummy") and even be portable (however, the user will have to avoid
> using any of the names in the std namespace).

This is really rolling out the big guns.  For vector, 

  #include <vector>
  using std::vector;

has the same useful effect without the smoke and carnage.   In fact, this 
is what <vector.h> has in it (look!).  To make your code portable later, 
you can provide your own "vector.h" with that in it, if you like.

Of course some of the other headers define many more global names.  Still, 
using-directives like Joe suggests invite trouble; a few using-declarations
as I have suggested above costs very little and helps keep your hair thick 
and dark.

The "using namespace" using-directive is *not* your friend.

Nathan Myers
ncm@cantrip.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]