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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-25 16:22:03 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer.de.kpn-eurorings.net!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: "Ekkehard Morgenstern" Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada Date: Wed, 26 Nov 2003 01:22:06 +0100 Organization: 1&1 Internet AG Message-ID: References: <21836716.smDW2dK3SM@linux1.krischik.com> NNTP-Posting-Host: p508c004b.dip0.t-ipconnect.de X-Trace: online.de 1069806123 25361 80.140.0.75 (26 Nov 2003 00:22:03 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Wed, 26 Nov 2003 00:22:03 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Xref: archiver1.google.com comp.lang.ada:2945 Date: 2003-11-26T01:22:06+01:00 List-Id: "Martin Krischik" schrieb im Newsbeitrag news:21836716.smDW2dK3SM@linux1.krischik.com... > Ekkehard Morgenstern wrote: > > Do I have to use class-wide types for object-oriented programming, or > > could I use regular access types? > > > > Like, when I declare a procedure > > > > procedure A ( B: in access all T'Class ) > > I made this mistake as well when I started. For OO it should be only: > > procedure A ( B: in out T ) > > Unlike C++ no access is needed in Ada. And a class wide Types make your > procedure non "virtual". Some Tutorials are quite bad about describing that > point. Are you sure? Should it not read at least procedure A ( B: in out T'Class ) Because when I inherit from a class I would like the methods of the base class to work on the derived class as well. Both the Ada Rationale and the Guide for C/C++ programmers say that you have to declare the first parameter of a procedure or the return value of a function to be of the class-wide type of the class to get the dynamic runtime dispatching behaviour from Ada (like virtual functions in C++). How would I have to declare them? And how do I cast an object back to the reduced record type? And is that necessary at all? I guess I'll have to write some simple test cases. > > procedure A ( B: in access all T ) > > Should be: > > procedure A ( B: access T ) > > and is Ok. The Ada 95 Reference says that the "all" attribute provides read-write access to the object, while omitting it would only provide read-only access? Or did I get that wrong? (btw, I made short cuts with my examples, I know not all of the notation I gave can be actually compiled) > > procedure A ( B: in out T ) > > Much better then using an acces type. But how about inheritance? Will the procedure operate on a type derived from T? > > procedure A ( B: in T ) > > Is like using "const&" in C++. How about function returns? Can I return a reference to an object in the same way? > In Ada access type are not as often needed as in C++. So don't use then > unless you need them. References are done automatily by Ada. > > If you know C++ then you will know about: > > virtual void A (T& B); or virtual void A (T B); > > As I said Ada will make the '&' Reference automaticly. Does that help to avoid casting as well? And how do I return a reference from a function? Or should I use procedures with in out parameters instead? > The "all" part is needed access to an object which have not been created > with "new". You mean it doesn't give access to an object that was elaborated normally? Now that explains some things. > Using "all" for an access might reduce performace since the > compiler might have to do some extra checking on the access. Avoid if not > needed. Ok. > > I would like to program as cleanly as possible in Ada right from the > > start, so I'd be glad if someone could give me some hints. :-) > > Hope I was of help. Yes, thank you. :-) > You might also browse my Web page http://adacl.sourceforge.net. There are > lots of sources you can browse right on the web without downloading them. Thanks, I have taken a look at it (not finished looking yet! ;-) ).