Topic: [--][??][**] Private namespace members in C++?


Author: biderd@abm.si
Date: 1996/08/12
Raw View
Namespaces indeed aren't suitable for an extensions like the ones
I proposed; it introduces problems regarding some of their other
features. The problem I demonstrated can be solved by using a class
with all members made static.

[There is also something similar to this that is referred to
as a Singleton class. Who or what is this Singleton, anyway?]


> Secondly, you can use unnamed namespaces to implement private
> members as follows:
> namespace A
> {
>   namespace {
>     int x,y,z; // only functions in A can access these!
>   };
> };

According to the April '95 draft (is that the newest?),
the above x,y,z members can be made globally accessible,
as in the following example:


using namespace A;
void f() {
     ++x; ++y; ++z;
}



Although the members of the nested unnamed namespace can be masked
with another, global one:

namespace A {
     namespace { int x, y, z; }
}
namespace {
     int x, y, z;
}

// A::unnamed1::x, A::unnamed1::y and A::unnamed1::z are masked by
//    unnamed2::x, unnamed2::y and unnamed2::z.


But this introduces other problems - members of the first unnamed
namespace can also mask things we don't want to mask.


denis (denis.bider@abm.si)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]