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=-1.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,b14a804025dceb20 X-Google-Attributes: gid103376,public From: Francois Godme Subject: Re: Constructors/Destructors in Ada95 Date: 2000/10/20 Message-ID: <39F0C9B9.EA30D529@bigfoot.com>#1/1 X-Deja-AN: 683969203 Content-Transfer-Encoding: 8bit References: <39EE160D.F0A2000@bigfoot.com> <39EF5431.BF4CD793@bigfoot.com> <39F0A6C7.E592AFFB@averstar.com> X-Accept-Language: fr, en-US, en Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@proxad.net X-Trace: nnrp3.proxad.net 972081434 212.27.43.118 (Sat, 21 Oct 2000 00:37:14 CEST) Organization: Guest of ProXad - France MIME-Version: 1.0 NNTP-Posting-Date: Sat, 21 Oct 2000 00:37:14 CEST Newsgroups: comp.lang.ada Date: 2000-10-20T00:00:00+00:00 List-Id: Tucker Taft a �crit : > It is a mistake to think that the Initialize procedure > represents Ada's "constructor" feature. As you recognize > below, Initialize is the rough equivalent of the default > constructor. For any other kind of constructor, you simply > write a function, or procedure with an [in] out parameter. > Ada also has a builtin constructor to simplify the > creation of these user-defined constructors, namely an aggregate > (array, record, or record extension). This is available > for non-limited types, in places where the type is > visible (e.g. inside the package where it is declared). > > An aggregate constructor can be combined with dynamic > storage allocation, via an initialized allocator. > Record aggregates are neat but can only be used in a white box approach on non-limited types. True, non-limited types can be initialized by functions but you have to be careful to not make these functions primitive operations. By using a 'class attribute on the return parameter type for example. > For (inherently) limited types, non-default construction must be > done essentially one component at a time, even when inside > the package where the type is defined. Of course, from outside > the package, an appropriate procedure would be called to > invoke the user-chosen construction operation, and that > procedure would take care of the appropriate component-by- > component actions. > Yes, but the drawback is that instances of limited types cannot be declared constant when they should be. In C++, instances of classes with private operator= and private operator== can be constant. > Initialize is exactly the part of the default constructor, > over and above the default initialization specified within > the type declaration itself. If the type extension adds > more components that have default initialization, these > default initializations will occur, even if Initialize is > inherited. In fact, I would generally recommend that > programmers minimize the use of Initialize, if they can > do it all with per-component default initialization. > Yes, they serve the same purpose with almost the same power. Constructors in C++ have another feature unknown in Ada which allows the creation of constant member attributes. It applies to any type. Not to a limited set of types which can be used as record discriminants.