Jim said:
what's that means by
using namespace pug;
namespaces were designed to prevent name collision. Such as some library
contianing a function foo, and another library containing a different
function foo. If you tried to use both libraries in your code, and call the
function foo, the compiler couldn't determine which foo you wanted to call,
there would be 2 of them, the names colided.
C++ came up with a way to prevent this problem, namespaces. So one library,
say you called it boost, would put it's functions in the namespace boost.
Another library would use it's own name. For example, my own functions I
put in a namespace called jml, my initials. So now with our hypothentical
function foo there is a boost::foo and a jml::foo. The compiler can
determine which one I am trying to use by namespace resolution. If I use
boost::foo() I am using the foo in the namespace boost. If I use jml::foo()
then I am using the foo in jml.
The standard template library uses the namespace std (for STanDard).
Some people don't like to type std:: all over to specify which namespace the
function is in. There are some shortcuts people can use. For example, in
the standard template library is a template container called vector. We can
use it like this:
std::vector<int> Data;
Some people not wanting to have to type std:: could use:
using std::vector;
then just have to do:
vector<int> Data;
This is because a using statement will bring whatever is specified into the
local namespace, also called the unnamed namespace. The unnamed namespace
is what is used if you don't give a namespace resolution.
foo();
means to call foo() in the unnamed namespace.
std::foo();
means to call foo() in the namespace std
Well, some people don't even want to specify what they want to use in the
library, they want to bring everything into the unnamed namespace, which is
where we finally get to your question.
using namespace pug;
means to bring *everything* that is in the namespace pug into the unnamed
space, so you don't have to use the namespace qualifer to call the
functions/methods/templates/whatever.
It is generally considered bad form to include everthing from a namespace
like this, however, as it defeates the purpose of namespaces in the first
place, avoiding name collisions. And it should never be done in a header
file.
Personally I, and a lot of people, never use the using clause and just
always specify the namespace.