From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,901038687c38f61c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: kevin.cline@gmail.com (Kevin Cline) Newsgroups: comp.lang.ada Subject: Re: Idiom for a class and an object in Ada Date: 21 Oct 2004 12:31:00 -0700 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 198.23.5.11 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1098387060 31943 127.0.0.1 (21 Oct 2004 19:31:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 21 Oct 2004 19:31:00 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:5594 Date: 2004-10-21T12:31:00-07:00 List-Id: Jeffrey Carter wrote in message news:... > Matthew Heaney wrote: > > > For reasons I can't fathom, many Ada95 developers still have a very > > Ada83 mindset. > > That's because Ada 83 was a very good language, and the idioms that were > good for it are still good. > > > This is the canonical idiom in C++ for controlling instance creation: > > > > class C { > > public: > > > > static C* make( /* ... */ ); > > static void free(C*); > > > > void f(); //whatever > > > > private: > > > > C(); > > C(const C&); > > > > ~C(); > > > > C& operator=(const C&); > > }; > > > > Here, the ctor (and dtor) is declared as private, so the only way to > > make a C object is by calling factory function C::make(). > > > > This has a direct translation into Ada95: > > > > package P is > > > > type T (<>) is limited private; > > > > procedure Op (O : in out T); > > > > type T_Access is access all T; > > > > function New_T (...) return T_Access; > > And this is why C++ is never a good guide to how to do things in Ada. > The pointer may well be needed in C++; Not in this case. class AD_Converter { private: AD_Converter(int line) {} public: static AD_Converter Noise; }; AD_Converter AD_Converter::Noise(17);