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,81cf52699486abe7 X-Google-Attributes: gid103376,public From: falis@ma.aonix.com (Ed Falis) Subject: Re: Ada95 Strengths/Weaknesses. Date: 1999/09/28 Message-ID: <1104_938481247@DZOG-CHEN>#1/1 X-Deja-AN: 530105619 Sender: news@sd.aonix.com (USENET News Admin @flash) X-Nntp-Posting-Host: 192.157.137.134 References: <37EED7B8.245C0054@yukyonline.co.yuky> <37EF9B98.7F817CC0@pwfl.com> Organization: Aonix, San Diego, CA, USA Newsgroups: comp.lang.ada Date: 1999-09-28T00:00:00+00:00 List-Id: On 27 Sep 1999 19:48:02 -0400, Hyman Rosen wrote: > Aside from the verbosity of the Ada code (which is apparent even though > the C++ equivalents aren't written idiomatically), notice that in the > output code, it is necessary to repeat the types of the things being > output, even though the ompiler already knows it! Not necessary. MDC is using a more verbose idiom than necessary to do the job. > > By the way, here's the C++ for your unimplemented third case - Not quite the same thing as he did. Below is Ada code that does what your C++ does. Let's not confuse style and substance (yes, it's still more verbose, partly because of multi-line routine definitions and your not using a header file). - Ed package Saver is type Save_Stuff (Name_Length: Natural) is private; function New_Save_Stuff (Str: String; Val: Integer) return Save_Stuff; procedure Put (S: in out Save_Stuff; X: Integer); function Get (S: Save_Stuff) return Integer; private type Save_Stuff (Name_Length: Natural) is record Name: String (1..Name_Length); Save: Integer; end record; end Saver; package body Saver is -- This is used because the C++ default access is private, right? function New_Save_Stuff (Str: String; Val: Integer) return Save_Stuff is begin return Save_Stuff'(Str'Length, Str, Val); end; procedure Put (S: in out Save_Stuff; X: Integer)is begin S.Save := X; end; function Get (S: Save_Stuff) return Integer is begin return S.Save; end; end Saver; with Saver; use Saver; with Ada.Text_Io, Ada.Integer_Text_Io; use Ada.Text_Io, Ada.Integer_Text_Io; procedure Main is My_Obj: Save_Stuff := New_Save_Stuff ("My Object", 55); Your_Obj: Save_Stuff := New_Save_Stuff ("Your Object", 55); begin Put (My_Obj, 23); Put ("The value of my object is "); Put (Get (My_Obj)); New_Line; Put (Your_Obj, 46); Put ("The value of your object is "); Put (Get (Your_Obj)); New_Line; end Main; > > #include > #include > > using namespace std; > > class SaveStuff > { > string name; > int save; > public: > Save_Stuff(string n = string(), int s = 0) : name(n), save(s) { } > void put(int x) { save = x; } > int get() const { return save; } > }; > > int main() > { > SaveStuff my_obj("My Object", 55); > SaveStuff your_obj("Your Object", 55); > > my_obj.put(23); > cout << "The value of my object is " << my_obj.get() << endl; > > your_obj.put(46); > cout << "The value of your object is " << your_obj.get() << endl; > } > >