From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: oo problem help please
Date: Tue, 09 Dec 2003 17:42:27 +0100
Date: 2003-12-09T17:42:27+01:00 [thread overview]
Message-ID: <1203233.17AvFJpsGG@linux1.krischik.com> (raw)
In-Reply-To: 4948f537.0312081149.70179416@posting.google.com
shoko wrote:
> what is wrong with the following code:
Wrong choices
> ----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;
>
I don't belive that every name should be 256 characters long.
> begin
>ᅵᅵᅵᅵᅵcars(1)ᅵ:=ᅵcar_ptr(initbus("mercedes"));
ᅵᅵ
Yes "mercedes" is not 256 Characters. You should take a look at
http://www.adaic.org/standards/95lrm/html/RM-A-4-4.html
http://www.adaic.org/standards/95lrm/html/RM-A-4-5.html
Fact is that you got the wrong type of string. If there is a max lenght
(like you want to store your vechicles in a database) then use
Ada.Strings.Bounded if not use Ada.Strings.Unbounded.
Or if the name is constant use a discriminant:
type car (
Name_Lenght : Positive)
is tagged record
name : String(1 .. Name_Lenght);
end record;
With Regards
Martin
--
mailto://krischik@users.sourceforge.net
http://adacl.sourceforge.net
prev parent reply other threads:[~2003-12-09 16:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-08 19:49 oo problem help please shoko
2003-12-08 23:19 ` Marius Amado Alves
2003-12-09 16:45 ` Martin Krischik
2003-12-09 16:42 ` Martin Krischik [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox