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 X-Google-Thread: 103376,92d1af21ade61406 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-30 00:13:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3DBF9437.8090408@worldnet.att.net> From: Jim Rogers User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Problems with 'class, help anyone? References: <3DBE2593.9080800@worldnet.att.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 30 Oct 2002 08:13:07 GMT NNTP-Posting-Host: 12.86.39.57 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1035965587 12.86.39.57 (Wed, 30 Oct 2002 08:13:07 GMT) NNTP-Posting-Date: Wed, 30 Oct 2002 08:13:07 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:30218 Date: 2002-10-30T08:13:07+00:00 List-Id: M�rten Woxberg wrote: > On Tue, 29 Oct 2002 06:08:40 +0000, Jim Rogers wrote: > > >>M�rten Woxberg wrote: >> >> > > > >>I see you are doing something *almost* exactly the same. The almost seems >>to be your problem. >> >>The GNAT error messages are pretty clear. To give you a detailed analysis of >>your code I would need to see your code, not just the compiler error messages. >> > > Ok I've tried the Code from the webpage now and that produces the same > errors.. thus it doesnt work with gnat either.. gnat is version 3.13 and > the code on the page was tested with 3.03 and 3.06 so it should > work shouldn't it? Several of the package specifications are presented with out corresponding package bodies. The class wide access types are defined as general access types, but the corresponding instances are not defined as aliased. The code frequently tries to make an instance of an abstract type. This is not allowed. In general, these examples are both incomplete and incorrect. You might try contacting Simon Johnston to find an errata page for this document. I have thrown together an example of using 'class that works. ----------------------------------------------------------------------- -- Person tagged type. -- A tagged type is an extensible data structure. ----------------------------------------------------------------------- with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package Persons is type Person is tagged private; procedure Set_Name (The_Person : out Person; Name : in String); function Get_Name(The_Person : Person) return String; procedure Set_Age(The_Person : out Person; Age : in Natural); function Get_Age(The_Person : Person) return Natural; procedure Display(The_Person : Person); package Builder is function Create(Name : String; Age : Natural) return Person; end Builder; procedure Print(The_Person : Person'Class); private type Person is tagged record Name : Unbounded_String := Null_Unbounded_String; Age : Natural := 0; end record; end Persons; with Ada.Text_Io; use Ada.Text_Io; package body Persons is procedure Set_Name ( The_Person : out Person; Name : in String ) is begin The_Person.Name := To_Unbounded_String(Name); end Set_Name; function Get_Name ( The_Person : Person ) return String is begin return To_String(The_Person.Name); end Get_Name; procedure Set_Age ( The_Person : out Person; Age : in Natural ) is begin The_Person.Age := Age; end Set_Age; function Get_Age ( The_Person : Person ) return Natural is begin return The_Person.Age; end Get_Age; procedure Display ( The_Person : Person ) is begin Put_Line(Get_Name(The_Person) & " is" & Integer'Image(Get_Age(The_Person)) & " years old."); end Display; package body Builder is function Create ( Name : String; Age : Natural ) return Person is Temp : Person; begin Set_Name(Temp, Name); Set_Age(Temp, Age); return Temp; end Create; end Builder; procedure Print ( The_Person : Person'Class ) is begin Display(The_Person); end Print; end Persons; with Persons; use Persons; package Employees is type Employee is new Person with private; procedure Set_Id ( The_Employee : out Employee; Id : in Positive ); function Get_Id ( The_Employee : Employee ) return Positive; procedure Display ( The_Employee : Employee ); package Builder is function Create ( Name : String; Age : Natural; Id : Positive ) return Employee; end Builder; private type Employee is new Person with record Id : Positive; end record; end Employees; with Ada.Text_Io; use Ada.Text_Io; package body Employees is procedure Set_Id ( The_Employee : out Employee; Id : in Positive ) is begin The_Employee.Id := Id; end Set_Id; function Get_Id ( The_Employee : Employee ) return Positive is begin return The_Employee.Id; end Get_Id; procedure Display ( The_Employee : Employee ) is begin Display(Person(The_Employee)); Put_Line("Id:" & Integer'Image(The_Employee.Id)); end Display; package body Builder is function Create ( Name : String; Age : Natural; Id : Positive ) return Employee is Temp : Employee; begin Set_Name(Temp, Name); Set_Age(Temp, Age); Set_Id(Temp, Id); return Temp; end Create; end Builder; end Employees; with Employees; use Employees; with Persons; use Persons; procedure Employee_Test is E1 : Employee := Employees.Builder.Create (Name => "Fred W. Flintstone", Age => 46, Id => 12345); E2 : Employee := Employees.Builder.Create (Name => "Barney Rubble", Age => 43, Id => 10101); P1 : Person := Persons.Builder.Create (Name => "Betty Rubble", Age => 39); begin Print(E1); Print(E2); Print(P1); end Employee_Test; Jim Rogers