Topic: Namespaces within class definition???


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1996/03/01
Raw View
In article s3c@nnrp1.news.primenet.com, kj7bg@primenet.com (Bob White) writes:
>...  I tried the following and it seems to work:
>
>typedef std::string XyzString;
>class xyz : public XyzString { }
>
>So I will use it until Borland and Microsoft allow me the more
>straight forward way.  Also, I am using the "string" class as defined by one
>version of the C++ standard which was put in the "std" namespace.  I thought
>this was what the current standard required!

Yes. The draft standard defines a string class called "string", and
all library elements are in the "std" namespace. You have basically
three ways to access names in the standard library:
1. Explicit qualification:
 std::string MyString;
2. A using-declaration:
 using std::string;
 string MyString;
3. A using-directive:
 using namespace std;
 string MyString;

The using-declaration (#2) places the specified name in the current scope
having its original declaration.

The using-directive (#3) makes all names from the namespace visible from
the current scope, which is subtly different from placing those names IN
the current scope. (And subtly different from placing them in a notional
surrounding scope.) See Stroustrup's "Design and Evolution of C++" for
more details.

Your typedef is a variation of #1.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]