Thursday, November 25, 2010

Using Declarations versus Using Directives

A using-declaration is different than a using-directive.

A using-declaration brings one name into a scope. This name can be used as if it was declared locally.
For example,
    using std::vector;
Note that the keyword 'namespace' is not used.
A using-directive brings all the names of the namespace into a scope.
For example,
    using namespace std;
You can also have a namespace alias, which can be used make a namespace name shorter or clearer.
For example,

    void widget();

Reference: The C++ Programming Language by Bjarne Stroustrup. Addison-Wesley, 2000, Section: 8.2.2-3

No comments:

Post a Comment