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,FREEMAIL_FROM, T_HK_NAME_FM_MR_MRS,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bbc77d6e9a74feb5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-07 20:46:27 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: ratsonjaniv@hotmail.com (Mr. J.) Newsgroups: comp.lang.ada Subject: Re: please help - access and inheritence Date: 7 Dec 2003 20:46:27 -0800 Organization: http://groups.google.com Message-ID: References: <3fd27939$1@news.barak.net.il> NNTP-Posting-Host: 82.166.164.61 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1070858787 5654 127.0.0.1 (8 Dec 2003 04:46:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 8 Dec 2003 04:46:27 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:3215 Date: 2003-12-07T20:46:27-08:00 List-Id: 10x, It works now. now, the next problem is as follow: The Code: =========================================================================== procedure Q1 is Maxvehilces : constant := 10; -- arbitrary type Vehicleptr is access all Jr.Vehicle.Vehicle'Class; type Vehiclesarr is array (1..Maxvehilces) of Vehicleptr; Arr: Vehiclesarr; Vp1,Vp2,Vp3,Vp4,Vp5: aliased Jr.Vehicle.Private_Car.Vehicle_Private; Vl6,Vl7,Vl8 : aliased Jr.Vehicle.Load.Vehicle_Load; Vp9,Vp10 : aliased Jr.Vehicle.Passengers.Vehicle_Passengers; Tmp :Vehicleptr; Speed: Natural; begin Daily_Max_Speed(Vp1,65); Daily_Max_Speed(Vp2,101); Daily_Max_Speed(Vp3,92); Daily_Max_Speed(Vp4,113); Daily_Max_Speed(Vp5,76); Daily_Max_Speed(Vl6,56); Daily_Max_Speed(Vl7,110); Daily_Max_Speed(Vl8,70); Daily_Max_Speed(Vp9,81); Daily_Max_Speed(Vp10,67); Arr(1) := Vp1'access; Arr(2) := Vp2'access; Arr(3) := Vp3'access; Arr(4) := Vp4'access; Arr(5) := Vp5'access; Arr(6) := Vl6'access; Arr(7) := Vl7'access; Arr(8) := Vl8'access; Arr(9) := Vp9'access; Arr(10) := Vp10'access; for I in Arr'range loop if(Has_Exceeded(Arr(2).all)) then Put_Line("Exceeded"); end if; end loop; end Q1; =========================================================================== Has_Exceeded is a virtual function, the base class: =========================================================================== package Jr.Vehicle is type Vehicle is abstract tagged private; Allowmaxspeed : Natural := 100; procedure Daily_Max_Speed(V: in out Vehicle; Speed: Natural); function Daily_Max_Speed(V:Vehicle) return Natural; function Has_Exceeded(V:Vehicle) return Boolean; function Treatment_Date(V:Vehicle;LastTreatment:Ada.Calendar.Time) return Ada.Calendar.Time; Illegalspeed: exception; --when daily max speed exceeded possible max speed private type Vehicle is new Controlled with record Possiblemaxspeed : Natural; Dailymaxspeed : Natural := 0; end record; procedure Initialize(V:in out Vehicle;Possiblemaxspeed:Natural); end Jr.Vehicle; =========================================================================== The Compiler Errors: --------------------------------------------------------------------------- q1.adb:64:13: no candidate interpretations match the actuals: q1.adb:64:33: expected private type "Vehicle_Private" defined at jr-vehicle-private_car.ads:5 q1.adb:64:33: found type "Vehicle'Class" defined at jr-vehicle.ads:7 q1.adb:64:33: ==> in call to "Has_Exceeded" at jr-vehicle-private_car.ads:5(inherited) q1.adb:64:33: ==> in call to "Has_Exceeded" at jr-vehicle-passengers.ads:7 q1.adb:64:33: ==> in call to "Has_Exceeded" at jr-vehicle-load.ads:7 End of compilation ---------------------------------------------------------------------------- 10x for your help. Jeffrey Carter wrote in message news:... > Ratson Janiv wrote: > > type Vehicleptr is access Jr.Vehicle.Vehicle'Class; > > > > type Vehiclesarr is array (1..Maxvehilces) of Vehicleptr; > > > > Vp1,Vp2,Vp3,Vp4,Vp5: aliased Jr.Vehicle.Private_Car.Vehicle_Private; > > > > Arr(1) := Vehicleptr(Vp1'access); -- failed, why? please ... > > You could be a bit more clear about what the problem is. Does "failed" > mean a run-time problem or a compiler error? In either case, more > information about the "failure" would be helpful. > > I note that Vehicleptr is not a general access type (access all > ), but only allows access to values allocated on the heap > (access ). Since Vp1'access does not designate a value > allocated on the heap, it cannot be assigned to an object of type > Vehicleptr. So if Arr (1) is a Vehicleptr [which seems likely, since > you're trying to convert Vp1'access to Vehicleptr before assigning it to > Arr (1)], the compiler should dissallow the assignment. > > If you define Vehicleptr as access all ..., and Arr is declared as > Vehiclesarr, then you can write > > Arr (1) := Vp1'access; > > I guess saving the time to type an underline is more important than > having code that is easy to read by using names such as Vehicle_Ptr.