From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Constructors with multiple inheritance
Date: Thu, 10 Nov 2011 20:39:27 +0100
Date: 2011-11-10T20:39:27+01:00 [thread overview]
Message-ID: <10xzoyh4rszmr$.s4ir5szcahvp.dlg@40tude.net> (raw)
In-Reply-To: j9h4eu$ha7$1@tornado.tornevall.net
On Thu, 10 Nov 2011 11:16:24 -0700, Jeffrey Carter wrote:
> On 11/09/2011 08:47 PM, Rego, P. wrote:
>>
>> class Par_Class {
>> public:
>> Par_Class (int aValue, const char *aName);
>>
>> private:
>> int theValue;
>> char *theName;
>> };
>
> private with Ada.Strings.Unbounded;
>
> package Par is
> type Class is private;
>
> function Create (Value : in Integer; Name : in String);
> private -- Par
> type Class is record
> Value : Integer := Integer'First;
> Name : Ada.Strings.Unbounded.Unbounded_String;
> end record;
> end Par;
>
> package body Par is
> function Create (Value : in Integer; Name : in String) is
> -- null;
> begin -- Create
> return Class'(Value => Value,
> Name => Ada.Strings.Unbounded.To_Unbounded_String (Name) );
> end Create;
> end Par;
>
> No need for tagged types or access types for this example.
No need in unbounded strings either:
type Class (<>) is private;
function Create (Value : in Integer; Name : in String) return Class;
private
type Class (Length : Natural) is record
Value : Integer := Integer'First;
Name : String (1..Length);
end record;
function Create (Value : in Integer; Name : in String) return Class is
begin
return (Length => Name'Length, Value => Value, Name => Name);
end Create;
IMO, unbounded strings should be used only in two cases:
1. The container type must be constrained (e.g. to place its objects into
arrays etc)
2. The component is varying during object's life.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2011-11-10 19:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-29 19:40 Constructors with multiple inheritance Rego, P.
2011-09-29 20:20 ` Dmitry A. Kazakov
2011-09-30 3:11 ` Rego, P.
2011-09-30 7:36 ` Dmitry A. Kazakov
2011-09-30 14:04 ` Rego, P.
2011-09-30 16:29 ` Robert A Duff
2011-09-30 19:14 ` Rego, P.
2011-09-30 16:42 ` Dmitry A. Kazakov
2011-09-30 19:42 ` Rego, P.
2011-10-06 12:46 ` Julian Leyh
2011-11-09 2:24 ` Rego, P.
2011-11-09 8:39 ` Dmitry A. Kazakov
2011-11-10 3:47 ` Rego, P.
2011-11-10 7:09 ` AdaMagica
2011-11-10 7:20 ` AdaMagica
2011-11-10 8:35 ` Dmitry A. Kazakov
2011-11-12 15:16 ` Rego, P.
2011-11-12 15:30 ` Rego, P.
2011-11-12 16:28 ` Dmitry A. Kazakov
2011-11-12 17:41 ` Rego, P.
2011-11-10 8:33 ` Simon Wright
2011-11-10 9:01 ` Georg Bauhaus
2011-11-10 9:09 ` Georg Bauhaus
2011-11-10 18:16 ` Jeffrey Carter
2011-11-10 19:39 ` Dmitry A. Kazakov [this message]
2011-11-09 9:00 ` Simon Wright
2011-11-10 3:54 ` Rego, P.
2011-10-07 0:08 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox