Topic: NIHCL C++ class library and X11's libXt both use Object


Author: ark@alice.att.com (Andrew Koenig)
Date: 11 Oct 92 13:27:53 GMT
Raw View
In article <1992Oct10.210145.12634@muddcs.claremont.edu> jason@jarthur.claremont.edu (Jason Merrill) writes:

> But then, suppose you're only using the NIHCL, and you don't really feel
> like typing NIHCL:: every time you want to use one of its classes.  I think
> that a 'with' directive, as per Ada, would be useful here...

Well, maybe.  Such things have a potential problem.  Suppose you have
something like this:

 int count = 0;

 void foo()
 {
  count++;
  // ...
 }

Suppose also that foo uses things from some library, which it brings into
its namespace with something like Ada's 'with' directive.

That means that if a future version of the library acquires a component
named "count," it will conflict with the global one, either by hiding it
or by causing an ambiguity.  Either way, the purpose of the feature has
not been fulfilled.

For that reason, I think it is much more important in general to be able
to import specific names than to import a namespace wholesale.  The latter
might be handy sometimes, but it is essentially always hazardous.
--
    --Andrew Koenig
      ark@europa.att.com




Author: jason@jarthur.claremont.edu (Jason Merrill)
Date: Sat, 10 Oct 1992 21:01:45 GMT
Raw View
In article <1992Oct10.022733.24514@netcom.com> geoff@netcom.com (Geoffrey Leach) writes:
>
>It appears that there is an unfortunate interaction between the C++
>class library NIHCL and X11's Xt intrinsics, in that both declare "Object".
>Is there a workaround, or am I missing something?

I think this shows up the massive shortcomings of C++'s namespace scheme.
Although as of 2.1 you can nest classes, you must define the entire class
inside the enclosing class (right?), which is not very practical for
something like the NIHCL (big header file).

Something like

class NIHCL {
    class Object;
    class ArrayOb;
    ...
}

would be useful.  Alternately, would declaring Object as

class NIHCL::Object {...}

without the forward declaration really hurt?

But then, suppose you're only using the NIHCL, and you don't really feel
like typing NIHCL:: every time you want to use one of its classes.  I think
that a 'with' directive, as per Ada, would be useful here...

--
Jason Merrill