C++ namespace extended

2 views
Skip to first unread message

Zorro

unread,
May 14, 2024, 5:51:15 PM5/14/24
to computer.lang.Z++
Namespace is intended for organizing and packaging libraries. C++ namespace is rudimentary and lacks a lot of desired functionality.
Below is a brief description of Z++ namespace.

Namespaces have privateprotected and public sections with same semantics as class. The private section is for internal use by the namespace. The protected section can be inherited in derivations, but otherwise is private. Only the public section of a namespace is accessible to users of the namespace. Thus, the public section is what a namespace exports to the outside world.

The definition of a namespace and its implementation can be separated. This allows including a namespace in multiple files of a project that are separately compiled without complications.

Namespace derivation is multiple-inheritance. A namespace can only derive from other namespaces. The default for derivation is public. Private and public derivations have the same semantics as for classes.

A namespace exports it public contents. A user accesses the exported contents of a namespace as: using namespace Name-of-namespace;
It is possible to end the availability of a namespace at any point in a program, as: endusing namespace Name-of namespace;
Public namespace items can also be accessed selectively, as: Name-of namespace::namespaceItem;

A large library may end up in name clashes for its own internal use. In that case, the library may need to use the namespace mechanism purely for internal matters. This means that the library needs to introduce a set of namespaces without allowing its users to access the contents of these namespaces.

To solve the above problem, a namespace can be specified protected. The semantics is that, a protected namespace can only be used in a derivation. In particular, users cannot directly access the contents of a protected namespace. Since derivation could be private, the contents of a protected namespace could remain hidden from the users of the derived namespace.

Thus, a large library can define several protected namespaces in order to avoid its own internal name clashes, without affecting the users of the library.

C++ is just a subset of Z++. Z++ is platform-independent and component-oriented.

For Z++ visit www.ZHMicro.com
Reply all
Reply to author
Forward
0 new messages