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,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e5eb8ca5dcea2827 X-Google-Attributes: gid103376,public From: Laurent Guerby Subject: Re: Ada OO Mechanism Date: 1999/05/26 Message-ID: <86iu9fhawg.fsf@ppp-101-91.villette.club-internet.fr>#1/1 X-Deja-AN: 482432426 References: <7i05aq$rgl$1@news.orbitworld.net> <7i17gj$1u1k@news2.newsguy.com> <7iems7$1vm@news2.newsguy.com> X-Trace: front4.grolier.fr 927747872 13592 194.158.101.91 (26 May 1999 19:44:32 GMT) Organization: Club-Internet (France) NNTP-Posting-Date: 26 May 1999 19:44:32 GMT Newsgroups: comp.lang.ada Date: 1999-05-26T19:44:32+00:00 List-Id: Hyman Rosen as > I believe this Ada -- > > generic > type S is abstract tagged private; > package P is > type T is abstract new S with private; > -- operations on T > private > type T is abstract new S with > record > -- additional components > end record; > end P; > > corrsponds to this C++ -- > [...] As for your quest of finding an example of an OO construct significantly easier in Ada than in C++, I don't think you'll find something were the difference in implementation is that great, the OO models are basically the same (but for multiple inheritance of course). I don't know if in C++ you can constrain a template type argument to be of a specific class (type and class in the Ada sense). Here is a slight variation of the Ada code you posted that uses this feature: package P is type T is tagged null record; -- T ops end P; with P; generic type GT is new P.T with private; -- This generic can be instanciated with any type in T'Class package G is -- I can call T ops on GT objects. type GGT is new GT with null record; -- GGT has T ops too. end G; The Ada OO model guarantees that no dispatch operation will run non-existing code (even in case of wild generics), I don't know if it's true of the C++ one. Okay, it doesn't make any OO construct easier, but you feel safer when this property is true ;-). Not directly linked to OO constructs (I agree in advance ;-): * In Ada, with discriminants you can easily have objects of varying size being stack allocated instead of heap allocated. On the notation size, I believe the Ada and C++ (vector<>) ways are equivalent but when you put parallelism in the loop it doesn't look quite the same, heap is global data so you have to lock when you use it, which can be troublesome in some cases performance-wise. * I don't know if self referencial types have a C++ equivalent (see the Ada rationale for an example of such beast). * You can "statically" create complex objects and elaboration issues are correctly handled by the Ada definition, I don't think it's the case in C++ (I think you don't know in what order the constructors will be called for "static" data in C++, I might be wrong). * What happens if a constructor or a destructor (C++ terminology) raises an exception is fully specified in Ada, in particular in case of a destructor exception, for each object in the scope its destructor is given a chance to run, when this is done a big general ooops exception is raised. I don't know if it is the case in C++. This applies too to function returning objects called as argument of another subprogam. --LG