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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,131f06967722ab4b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Ada 2005? Date: Sat, 18 Dec 2004 09:51:48 +0100 Organization: None Message-ID: <1258920.S9jBcL00t9@linux1.krischik.com> References: <1103344064.372396.51420@c13g2000cwb.googlegroups.com> Reply-To: martin@krischik.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1103362917 00 22211 pZI+XJmLXqFjv5H 041218 09:41:57 X-Complaints-To: usenet-abuse@t-online.de X-ID: E4pvKmZc8eOEvmTt5f7ZzzYiFOdKaTZgfXHVMZUlNYuke1rYgNMTop User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:7046 Date: 2004-12-18T09:51:48+01:00 List-Id: conradwt@runbox.com wrote: > Hi, will Ada support keyword class for designing and implementing > classes? For example, I'm forced to convert the following C++ class in > Ada as follows: > > // C++ > > class A_Device { > > public: > > A_Device( char*, int, int ); > > char* Name( void ); > > int Major( void ); > > int Minor( void ); > > protected: > > char* name; > > int major; > > int minor; > }; > > // Now, if I need to interact with the, this class I can do the > // following: > > void main(void) { > > A_Device aDevice = new A_Device( "Test", 1, 1 ); > > cout << aDevice.Name() << endl; > cout << aDevice.Major() << endl; > cout << aDevice.Minor() << endl; > > } > > // Ada > > package Devices is > > type Device is tagged private; > > type Device_Type is access private; You do to much pointer work! Ada does not need that much pointer work! Read: http://en.wikibooks.org/wiki/Programming:Ada:OO#The_class-wide_type > function Create( Name : String, > Major : Integer, > Minor : Integer ) return Device_Type; > > function Name( this : Device_Type ) return String; You did the equivalent of: class Device { static char* Name(Device* this); } A "static" class member will not dispatch! You should have done: function Name( this : in Device) return String; or function Name( this : in out Device) return String; Read: http://en.wikibooks.org/wiki/Programming:Ada:OO#Primitive_Operations > > function Major( this : Device_Type ) return Integer; > > function Minor( this : Device_Type ) return Integer; > > private > > type Device is tagged > > record > > name : String(1..20); > major: Integer; > minor: Integer; > > end record; > > end Devices; > > Now, interact with Ada package I would need to do the following: > > procedure main > > aDevice : Device_Type := Devices.Create( "Test", 1, 1 ); > > begin > > Put_Line( Name( aDevice ) ); > Put_Line( Major( aDevice ) ); > Put_line( Minor( aDevice ) ); > end main; > > It seems that I'm trying to mimic the behavior of a OO language in a > procedural language when converting C++ to Ada. Is this correct? No! Ada has OO - but you have not read enough tutorials to know how Ada's OO works. Keep going and you get there! > If > so, why doesn't Ada have OO contructs similar to C++, > Java, Eiffel, and Smalltalk to name a few where one passes a message to > an instance of a class? Ada does have these features! The difference is that Ada is package (namespace) centric and not record (struct) centric. In fact a Ada class need to be defined inside a package (namespace)! It is not uncomme to declare a classes like this: package Parent_Class is type Object is tagged record ..... end record; end Class_Name; with Parent_Class; package Child_Class is type Object is new Parent_Class.Object with record ..... end record; end Class_Name; > Will this be something in Ada 2005 because I > have been able to find a good overview of the language to date? Only interfaces are added to Ada 2005 - everything else is allready there. With Rergards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com