Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.std.c++ Subject: Re: "module" facility for top-level namespace control Keywords: namespace, module Message-ID: <72004@microsoft.UUCP> Date: 22 Apr 91 22:35:05 GMT References: <1991Apr19.163253.22253@kestrel.edu> <1991Apr19.183922.1982@kodak.kodak.com> <5143@lupine.NCD.COM> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Distribution: comp.std.c++ Organization: Microsoft Corp., Redmond WA Lines: 65 In article <5143@lupine.NCD.COM> rfg@NCD.COM (Ron Guilmette) writes: |The problem is *not* one of establishing new "modules" or new "namespaces" |(which class declarations can do quite well, thank you). No. The problem |is that if you do this, it becomes quite cumbersome to *reference* the |things whose declarations you have now nested within class declarations. |Specifically, it is quite irritating to have to write out the extra |CLASSNAME:: qualification all over the place. | |How can this problem (i.e. the *real* problem) be solved? C++ already has several "solutions" to these kinds of problems: 1) Within a member function "this->" is the default 2) Within a class inherited classnames are the default 3) Using references you can use shorthand names .... Substituting "module" for "class" in the above list leads to many ideas. Here's some examples: // the following silly #defines are introduced just to help show what // I'm talking about: #define MODULE class #define USE : MODULE XYZCorpClasses { public: static int intThing; class Object { public: void doSomething(); }; // .... }; MODULE ABCCorpClasses { public: class Object { public: void doSomething(); }; // .... }; MODULE MyClasses USE public XYZCorpClasses { public: class Derived : public Object { public: void doSomething(); }; static void main() { // let's try using some XYZ stuff by default: Object object; object.doSomething(); Derived dirv; dirv.doSomething(); // now let's use some non-default ABC stuff instead: ABCCorpClasses::Object abcOb; abcOb.doSomething(); // or explicitly use XYZ stuff if we like: XYZCorpClasses::Object xyzOb; xyzOb.doSomething(); } }; void main() { MyClasses::main(); }