C++ philosophy - using clause in header files

P

puzzlecracker

I heard different school of thoughts but most of the seem to agreet
that it is a bad idea to include

using namaspace std; in header files, even though it is non-issue (for
the most part - unless someone purposely created,for example, cout type
for some crazy reason). Anyone one would argue about cluause using and
how should it be used and abused?


Thanks
 
R

Ravi

There is more than just "cout" in the std namespace. Even then, cout,
could easily have been some variable name in a C-Library that needs to
be ported to C++. If some library included using namespace std in a
header file it would defeat the purpose of namespaces altogether. Why
have namespaces if they are already always imported?

Also consider the concept of "point of view" for a application
designer, using the using directive in a header probably isn't that
consequential. For a library designer, or even complex application
designer, it is extremely bad. Symbol pollution can get really hairy in
large projects.
 
A

AnonMail2005

Sutter's More Exceptional C++ has a good discussion on this point.
He states the case (convincingly) not to place these statements in
header files.

In a nutshell, certain using statements can cause a header file
to depend on the order of include statements in the header file.
That alone should scare you away from placing them there.

Look to that book or his website for further details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,303
Latest member
Ketonara

Latest Threads

Top