Topic: namespaces
Author: rad6938@tntech.edu (Rad)
Date: 9 Jul 94 12:06:29 -0600 Raw View
In article <2vjnq0$c3v@cherokee.advtech.uswest.com>, gsternberg@advtech.uswest.com writes:
> I've been hearing and reading posts about namespaces. I think I
> understand what a namespace is but I'm not quite clear on what the
> addition of this to C++ is supposed to fix/help. Could someone
> enlighten me ?
Namespaces are supposed to fix/help the problem of "namespace polution".
Have you ever had a problem where you accidently used a global name that was
the some as some library function/variable or maybe the same as someone else in
a project group was using. Namespaces will reduce the likelihood of these
problems. For example all the standard library functions should be placed in
one namespace ("std" I think) and if you happen to use an identical name in
your own namespace the compiler can will be able to tell the difference.
This also helps protect you from names added to the standard libraries in
the future.
----------------------------------------------------------------------------
Richard Deken Graduate student in electrical engineering
PGP public key available Tennessee Technological University
Internet: rad6938@gemini.tntech.edu Cookeville, TN, USA
Author: davem@eden.rutgers.edu (David Miller)
Date: 10 Jul 94 02:51:13 GMT Raw View
gsternberg@advtech.uswest.com wrote:
: I've been hearing and reading posts about namespaces. I think I
: understand what a namespace is but I'm not quite clear on what the
: addition of this to C++ is supposed to fix/help. Could someone
: enlighten me ?
It is intended to help solve the global namespace pollution
problem that can occur when using multiple libraries. It will make the
integration between libraries made by different companies less of a
snag than it is now. Observe the following:
Say you are writing a serial port monitoring system for SLIP that uses
an X11 based C++ librarie and a C++ SLIP library made by some other
manufacturer. You might run into the following problem.
/* X11C++.h */
class Window : public GC, public Colormap {
/* */
};
/* SLIP_C++.h */
class Window : public Client, private TCPIP {
/* */
};
Oops... You cannot use these libraries at the same time with out some
nested type trickery. With namespaces you can do the following:
namespace X11R5 {
#include <X11C++.h>
}
namespace SLIP {
#include <SLIP_C++.h>
}
using X11R5 {
Window X11_window;
X11_window.size = DEFAULT;
}
using SLIP {
WIndow SLIP_window;
SLIP_window.size = 10;
}
Get the idea?
Later,
David S. Miller
davem@eden.rutgers.edu
: Thanks,
: Greg Sternberg | "I don't know, I'm making this
: CompuServ: 71155,67 | up as I go along" - Indiana
: Internet: gsternberg@advtech.uswest.com | Jones, Raiders of the Lost Ark
: gsternbe@nyx.csu.du.edu |
Author: rbotting@wiley.csusb.edu (Dr. Richard Botting)
Date: 13 Jul 1994 14:14:14 GMT Raw View
Could somebody post some syntax (preferably approximating a standard!)
for the "namespace" construct, and how it is fitted into C++ syntax?
--
rbotting@wiley.csusb.edu.
rbotting::=`Dr. Richard J. Botting`, wiley::=`Faculty EMail System`,
csusb::=`California State University, San Bernardino, CA 92407, USA`.
Aka::=`dick@doc.csci.csusb.edu`.
Disclaimer::=`CSUSB may or may not agree with this message`.
Copyright(1994)::=`Copy and use as you wish as long as you include this
copyright and signature`.
Send EMail to gradinfo@silicon.csci.csusb.edu for info on a new
Masters degree in Computer Science!
Author: gsternberg@advtech.uswest.com
Date: 8 Jul 1994 14:28:16 GMT Raw View
I've been hearing and reading posts about namespaces. I think I
understand what a namespace is but I'm not quite clear on what the
addition of this to C++ is supposed to fix/help. Could someone
enlighten me ?
Thanks,
Greg Sternberg | "I don't know, I'm making this
CompuServ: 71155,67 | up as I go along" - Indiana
Internet: gsternberg@advtech.uswest.com | Jones, Raiders of the Lost Ark
gsternbe@nyx.csu.du.edu |