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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fcc68f44249afbd4 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!feeder6.cambrium.nl!feed.tweaknews.nl!feed.xsnews.nl!border-1.ams.xsnews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer0.kpn.DE!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 10 Jul 2007 10:07:12 +0200 From: Georg Bauhaus Organization: # User-Agent: Thunderbird 1.5.0.12 (Macintosh/20070509) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Translating C++ class types into Ada tagged types? References: <1184031587.650366.207550@m37g2000prh.googlegroups.com> <1184033524.336233.241450@d30g2000prg.googlegroups.com> In-Reply-To: <1184033524.336233.241450@d30g2000prg.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <46933d57$0$21008$9b4e6d93@newsspool1.arcor-online.net> NNTP-Posting-Date: 10 Jul 2007 10:03:36 CEST NNTP-Posting-Host: b7da8208.newsspool1.arcor-online.net X-Trace: DXC=kRG06Wobg=?Tia]Ho99G50ic==]BZ:af>4Fo<]lROoR1Fl8W>\BH3Y2PKkFi:O88a7A:ho7QcPOV3RHO jimmaureenrogers@worldnet.att.net wrote: > > Ada is object oriented, but does not provide constructors or > destructors. The following code is similar to your example > without constructors or destructors. Just to add that Ada does have construction and destruction (I am sure Jim Rogers knows them well), the language provides a number of ways to make sure that initialization and finalization takes place (and when it takes place!). So "Cat Frisky(5)" can be expressed in Ada as well, just not using constructors as in C++. One such facility well suited to polymorphic objects uses a factory function such as function Make (species: String; age: Natural) return Animal'class; -- an animal as requested in `species`, `age` years old where Animal could be a superclass of Cat in C++ terms. The 'class in Animal'class means that Make will return an object from the Animal hierarchy. If you wanted just a Cat or more specific heirs of Cat, say a cat that has fur of some color, use function Make (fur_color: Color; age: Natural) return Cat'class; -- some cat whose fur has the given `fur_color`, -- `age` years old And, finally, a simple construction function for Cat specifically and not heirs, but simply Cats could be function Make (age: Natural) return Cat; -- a cat, `age` years old (Unlike C++, Ada can use the type of the return value (Cat) in order to decide what specific type of object to expect on the LHS of ":=", for example.) This isn't the only way to initialize objects, either at run-time, or at compile time. In particular, you can have default initialization etc.. -- Georg