comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Problem Eliminating constructors
Date: Tue, 21 Jan 2003 10:44:37 +0100
Date: 2003-01-21T10:44:37+01:00	[thread overview]
Message-ID: <1n4q2v05i0cn9jnpdelrtroe9l0a7k2noh@4ax.com> (raw)
In-Reply-To: 3e2c66a7$0$33929$bed64819@news.gradwell.net

On Tue, 21 Jan 2003 02:07:29 +0500, porton@ex-code.com (Victor Porton)
wrote:

>In article <3E2BDFD8.4070805@epfl.ch>,
>	Rodrigo Garc�a <rodrigo.garcia@epfl.ch> writes:
>> Victor Porton wrote:
>>> package A is
>>> 
>>>   type A_Type is tagged
>>>     record
>>>       X: Integer;
>>>     end;
>>>     
>>>   function Create(X: Integer) return A_Type; -- guess what is the body
>>>   
>>> end A;
>>> 
>>> Then I have
>>> 
>>> type B_Type is new A.A_Type with
>>>   record
>>>     Y: Integer;
>>>   end;
>>> 
>>> Compiler requires me to override Create as the return type changes.
>>> But it is meaningless as now I need Create with two parameters
>>> instead of one.
>>> 
>>> What to do?
>> 
>>    You do not need a constructor for this simple case. This will create 
>> an A_Type object and initialize X to value 5.
>> 
>>    declare
>>       My_A : A.A_Type := (X => 5);
>[skip]
>
>Oh, Rodrigo, I oversimplified the real situation. Initialization with
>just aggregates is possible only in the example, really I need namely
>constructor functions.

Ada has constructor function. IMO what it does need is user-defined
contructors. However, most of Ada people do not share my opinion. In
any case (your statement below) constructors always *covariant*.

>Well, currently I switched to initialization by calling a procedure.
>
>It would be nice if Ada0X would allow to make a primitive operation
>non-virtual.

It is pretty dangerous, so there has to be a strong rationale for this
(i.e. to allow contravariant parameters). In your case, you could make
Create class-wide, if you want to overload it:

 function Create (X : Integer) return A_Type'Class;
   -- creates A_Type

function Create (X, Y : Integer) return B_Type'Class;
   -- creates B_Type

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-01-21  9:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-17  0:19 Problem Eliminating constructors Victor Porton
2003-01-17 15:21 ` John English
2003-01-17 21:10 ` Victor Porton
2003-01-18 15:19 ` Simon Wright
2003-01-20 11:39 ` Rodrigo García
2003-01-20 21:07 ` Victor Porton
2003-01-21  9:44   ` Dmitry A. Kazakov [this message]
2003-01-21 19:01     ` Martin Krischik
2003-01-21 11:43   ` Rodrigo García
2003-01-21 15:03   ` Stephen Leake
2003-01-21 13:09 ` Victor Porton
2003-01-22 15:26   ` Rodrigo García
2003-01-21 18:38 ` Victor Porton
2003-01-23 17:08   ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2003-01-17  6:54 Grein, Christoph
replies disabled

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