comp.lang.ada
 help / color / mirror / Atom feed
From: ratsonjaniv@hotmail.com (Mr. J.)
Subject: Re: please help - access and inheritence
Date: 7 Dec 2003 20:46:27 -0800
Date: 2003-12-07T20:46:27-08:00	[thread overview]
Message-ID: <fc116fae.0312072046.1efbe825@posting.google.com> (raw)
In-Reply-To: lyKAb.4224$rP6.87@newsread2.news.pas.earthlink.net

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 <spam@spam.com> wrote in message news:<lyKAb.4224$rP6.87@newsread2.news.pas.earthlink.net>...
> 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 
> <subtype>), but only allows access to values allocated on the heap 
> (access <subtype>). 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.



  reply	other threads:[~2003-12-08  4:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-07  0:47 please help - access and inheritence Ratson Janiv
2003-12-07  7:14 ` tmoran
2003-12-07 18:44 ` Jeffrey Carter
2003-12-08  4:46   ` Mr. J. [this message]
2003-12-08 18:07     ` Jeffrey Carter
2003-12-08 19:05       ` Martin Krischik
2003-12-08 19:17     ` Martin Krischik
2003-12-08 18:50 ` Martin Krischik
2003-12-09  5:58   ` Mr. J.
2003-12-09 16:55     ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox