Topic: Q: Private section in namespace?
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1997/10/28 Raw View
Cristian Georgescu wrote:
>
> Is there a private section in namespaces (or a way to simulate this with
> other constructs)?
>
> This should be in the intent to make a whole class private in a package.
If this class needs to be defined in one .cc file only, it's just
easy to do: Put the definition into a unnamed namespace, like the
following:
namespace mylib
{
// the following classes are private to this file:
namespace // unnamed
{
class one {};
class two {};
}
// the following class is accessible from anywhere
class three {};
}
Unfortunately this approach will not work in header files
(for each file including it, there will be created a _new_
unnamed namespace, giving a lot of classes mylib::(unnamed)::one
and mylib::(unnamed)::two, having no relation to each other).
This means that you can't f.ex. derive "public" classes from
"private" classes, because you can't repeat the definition of
them (you *can* however use pointers or references to those classes;
thus giving a way to enforce reference semantics to a class).
---
[ comp.std.c++ is moderated. 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 ]
Author: Steve Clamage <stephen.clamage_nospam@eng.sun.com>
Date: 1997/09/20 Raw View
Cristian Georgescu wrote:
>
> Is there a private section in namespaces (or a way to simulate this with
> other constructs)?
>
> This should be in the intent to make a whole class private in a package.
Namespaces provide only scope control. Their purpose is to allow
different libraries to co-exist in the same program even if they
have conflicting identifiers.
namespace A { enum DayOfWeek { SUN, mon, tues, WED, thurs, fri, sat }; }
namespace B { enum MaritalStatus { single, WED, divorced }; }
namespace C { enum Manufacturer { ibm, SUN, sgi, DEC }; }
namespace D { enum NumberBase { oct, DEC, hex }; }
If you want to restrict access, use a class, which also provides
scope control.
class X { private: enum NumberBase { oct, dec, hex }; };
class Y { private: enum Manufacturer { ibm, sun, sgi, dec }; };
--
Steve Clamage, stephen.clamage_nospam@eng.sun.com
( Note: remove "_nospam" when replying )
---
[ comp.std.c++ is moderated. 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 ]
Author: "Cristian Georgescu" <Cristian.Georgescu@worldnet.att.net>
Date: 1997/09/23 Raw View
Steve Clamage <stephen.clamage_nospam@eng.sun.com> wrote in article
<3422A3C6.6B1E@Eng.Sun.COM>...
> Cristian Georgescu wrote:
> >
> > Is there a private section in namespaces (or a way to simulate this
with
> > other constructs)?
> >
> > This should be in the intent to make a whole class private in a
package.
>
> Namespaces provide only scope control. Their purpose is to allow
> different libraries to co-exist in the same program even if they
> have conflicting identifiers.
> [...]
> If you want to restrict access, use a class, which also provides
> scope control.
In fact I am looking for a way to include some classes in a package
(library) that are used in "private" only for the implementation of that
package. I want the other classes of the package to be able to use these
private classes, but I do not want that the users of the library be able to
access or use these private classes.
Now, C++ provides a fine access control at class level, but does very
little in organizing class hierarchies. For instance (and IMHO) it lacks a
"package" entity that would allow to group classes. A package could then
have a private part just for the purpose I need.
However, looking at the existing constructs in C++ I figure that the
namespace would be a good candidate for a "package" and packaging classes.
All it lacks is a private section.
Using a class for simulating package looks somehow bizare to me. But then I
guess that your suggestion is the only workaround to the lack of a
"package" concept in C++.
--
Cristian Georgescu
_________________________________________________
Smith Industries
Aerospace & Defense Systems
7-9 Vreeland Road,
Florham Park, NJ 07932, USA.
_________________________________________________
E-mail: Georgescu_Christian@si.com
---
[ 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
]
Author: "Cristian Georgescu" <Cristian.Georgescu@worldnet.att.net>
Date: 1997/09/18 Raw View
Is there a private section in namespaces (or a way to simulate this with
other constructs)?
This should be in the intent to make a whole class private in a package.
--
Cristian Georgescu
_________________________________________________
Smith Industries
Aerospace & Defense Systems
7-9 Vreeland Road,
Florham Park, NJ 07932, USA.
_________________________________________________
E-mail: Georgescu_Christian@si.com
---
[ 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
]