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,e01befd2b86cac20 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news2.telebyte.nl!news-fra1.dfn.de!newsfeed.hanau.net!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: problems with classes Date: Fri, 01 Oct 2004 09:58:30 +0200 Organization: AdaCL Message-ID: <6816392.6CG8qeS1SM@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1096622420 05 26291 bY9kX5nr-4luxYN 041001 09:20:20 X-Complaints-To: usenet-abuse@t-online.de X-ID: ZGpsl-ZDZeUr+wcERC-1xIEN-j-+O+jb2DQyonqiedC4ED5zNHuHgb User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:4496 Date: 2004-10-01T09:58:30+02:00 List-Id: Rick Santa-Cruz wrote: > Hi, > > First of all I wanna thank all people in this group for the help. I am > just a beginner in Ada and before I started Ada, I thought that cause I > know C++ very well, it would be easy for me to understand Ada (in fact I > made this experience with learning programmin languages like Java, Perl, > C#, etc. after working a lot with C++). But this assumption was totally > wrong. The syntax of Ada seems to me a bit strange, at least at the moment > ;), but I am working hard to become better in Ada... > > Here are 2 examples of source-codes: > 1. Source1: > package Source_1 is > type Parent_Class is tagged > record > Number: Integer; > end record; > type Child_Class is new Parent_Class with private; > > procedure Parent_Proc(P: Parent_Class); > procedure Child_Proc(C: Child_Class); > > private > type Child_Class is new Parent_Class with > record > Number2: Integer; > end record; > end Source_1; > --------------------------------------------------------------------- > 1. Source2: > package Source_2 is > type Parent_Class is tagged > record > Number: Integer; > end record; > type Child_Class is new Parent_Class with > record > Number2: Integer; > end record; > > procedure Parent_Proc(P: Parent_Class); > procedure Child_Proc(C: Child_Class); > end Source_2; > > My question is now, why in the seconde code-example I get an error, that > Parent_Class has to be declared ready, before I define the Child_Class? > Why I don't get this error in the first case, cause there I specify the > Child_Class with: "type Child_Class is new Parent_Class with private;", > before I declare the procedure of the class Parent_Class? > If this would be C++, I think I would know the answer... so in C++ > "something like this" exists, too. It is called pre-definition of a type. > That means that, for example if I need the name of a type before I wanna > specify it, I can just write: > class MyType; > and specify it later. Is this the case in Ada too? Because die declared Parent_Proc after the "full view" of Child_Class. To declare the "full view" of Child_Class Parent_Proc need to be "frozen". When a type is "frozen" you can't make any changes to it. And for a class that means, you can't add another method. Try: package Source_2 is type Parent_Class is tagged record Number: Integer; end record; procedure Parent_Proc(P: Parent_Class); type Child_Class is new Parent_Class with record Number2: Integer; end record; procedure Child_Proc(C: Child_Class); end Source_2; And: package Source_1 is type Parent_Class is tagged private; type Child_Class is new Parent_Class with private; procedure Parent_Proc(P: Parent_Class); procedure Child_Proc(C: Child_Class); private type Parent_Class is tagged record Number: Integer; end record; type Child_Class is new Parent_Class with record Number2: Integer; end record; end Source_1; And see what happens. Last not least: Usually one defines only one class per package. That's unlike C++ where tons of classes share one namespace. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com