From: shoko2004@hotmail.com (shoko)
Subject: oo problem help please
Date: 8 Dec 2003 11:49:19 -0800
Date: 2003-12-08T11:49:19-08:00 [thread overview]
Message-ID: <4948f537.0312081149.70179416@posting.google.com> (raw)
what is wrong with the following code:
----car.ads----
package car is
--car class --
type car is tagged private;
type car_ptr is access all car'class;
--car methods --
procedure set_name(name:String;this:in out car);
function get_name(this:car) return string;
private
type car is tagged
record
name:String(1..256);
end record;
end car;
---car.adb---
package body car is
procedure set_name(name:String;This:in out car)is
begin
this.name:=name;
end set_name;
function get_name(this:car) return string is
begin
return this.name;
end get_name;
end car;
----transport.ads-----
with car;
package transport is
type transport_rec is new car.car with private;
type transport_Ptr is access all transport_rec'Class;
function init_transport(maximum_speed:positive) return transport_Ptr;
private
type transport_rec is new car.car with null record;
end transport;
-----transport.adb----
package body transport is
function init_transport(maximum_speed:positive)return transport_Ptr is
This: transport_Ptr;
begin
This:= new transport_Rec;
return this;
end init_transport;
end transport;
----------bus.ads---
with transport;
package bus is
type bus is new transport.transport_rec with private ;
type bus_Ptr is access all bus'Class;
function initbus(name:string) return bus_Ptr;
private
type bus is new transport.transport_rec with null record;
end bus;
---------bus.adb--------
package body bus is
function initbus(name:String) return bus_Ptr is
This: bus_ptr;
begin
This := new bus;
set_name(name,this.all); <-- CONSTRAINT ERROR
return this;
end initbus;
end bus;
------------------------------
and finally
--------main.adb--------------
with car;use car;
with bus;use bus;
procedure main is
cars:array(1..2) of car_ptr;
new_bus:bus_ptr;
begin
cars(1) := car_ptr(initbus("mercedes"));
end main;
the problem is that i get constraint error when the code is executed
why???
next reply other threads:[~2003-12-08 19:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-08 19:49 shoko [this message]
2003-12-08 23:19 ` oo problem help please Marius Amado Alves
2003-12-09 16:45 ` Martin Krischik
2003-12-09 16:42 ` 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