comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de>
Subject: Re: Constructors with multiple inheritance
Date: Thu, 10 Nov 2011 10:01:12 +0100
Date: 2011-11-10T10:01:14+01:00	[thread overview]
Message-ID: <4ebb92d9$0$6640$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <6366850.176.1320896821400.JavaMail.geo-discussion-forums@yqcm23>

On 11/10/11 4:47 AM, Rego, P. wrote:

> The compiler says me that Par_Obj is null when I use Par_Obj := Par_Obj.Construct, and I know it, and agree with it, because exactly what I want to do is to initialize my object (and so the object is not null anymore), so I can access other stuffs which are not shown here. I don't want to have a Constructor without class parameter (so according to Ada 2005 Rationale it would not be a method of the class Par_Class), because it runs away from my system architecture.

Ada, not exactly like C++, defines a function Construct returning
a type Par_Class object such that

(1) result type Par_Class belongs to the parameter profile of
     function  Construct just  like any other parameter

(2) function Construct is a member of the set of primitive subprograms
     of the type Par_Class (a "method"), agreeing with (1)

Your diagnosis seems influenced by a (mis-)understanding that
stems from C++. The diagnosis does not apply to Ada functions,
for two reasons.

First, Ada functions' results can and will take part in dispatching
by result type. Just like other parameters. There is no need
to pass a ***_Ptr to this effect (that it will not have).

Therefore, if you just write a function whose result type is Par_Class,
then the function is a "method" of type Par_Class.  Christoph has show
how to do this, see the package in AdaMagica's latest posting.

Second, note that even in C++, the constructor is *not* a method
of the class.  It does not return a pointer. Even when there is
the "this" pointer within the definitions of the class. (So
when I declare an object of a C++ class like

    Par_Class x = Par_Class(6, "foo"); // C++

then this is just fine without pointers.)

To be more like C++ then, function Construct would simply return an
object of type Par_Class, like Christoph has show.

Is it required in your case that every component of Par_Class should
be a pointer to an object, even those of some integer type?
You could write (later, not in the package defining type Par_Class)
declare

    X : Par_Class :=  Par_Class'(Construct(6, "foo"));

or

    type All_Those_Par_Classes_Ref is access Par_Class'Class;

    X : All_Those_Par_Classes_Ref := new Some_Par_Class'(Construct(a, b, c));

where the first Construct function is the primitive subprogram
of type Par_Class; and the seconds Construct function is overriding
it for a type Some_Par_Class that itself is derived from Par_Class.


As a final remark, mentioning "class" when discussing Ada can be confusing
unless "class" should mean class-wide, a type that only T'Class will denote.



  parent reply	other threads:[~2011-11-10  9:01 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 [this message]
2011-11-10  9:09                   ` Georg Bauhaus
2011-11-10 18:16                 ` Jeffrey Carter
2011-11-10 19:39                   ` Dmitry A. Kazakov
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