comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Constructors with multiple inheritance
Date: Thu, 6 Oct 2011 17:08:23 -0700 (PDT)
Date: 2011-10-06T17:08:23-07:00	[thread overview]
Message-ID: <eeef4d2f-958b-4ce2-bf1b-9b924ec72566@q24g2000vby.googlegroups.com> (raw)
In-Reply-To: 11513972.2788.1317325228383.JavaMail.geo-discussion-forums@yqnv12

On Sep 29, 2:40 pm, "Rego, P." <pvr...@gmail.com> wrote:
> Hi people
>
> I have a package which implements a class with two items which actually are classes which builds different kind of queues. One of them is a queue whose items are of the kind of the parent class. I need to implement a constructor to the parent class, then I need to implement the constructors for the two queues. For me, it`s more intuitive from OO point of view that the three constructors are implemented as methods (not just independent calls), and that was just the point where I got stuck.
>
> So, the packages are declared as
>
> ------------------------
> -- parent_package.ads --
> ------------------------
> limited with Parent_Package.Child_Package;
> package Parent_Package is
>    type Parent_Class is tagged
>       record
>          Child : access Child_Package.Parent_Queue_Class;
>          Modes : access Child_Package.Modes_Queue_Class;
>       end record;
>    type Parent_Class_Ptr is access all Parent_Class;
>    function Construct (Sender : in Parent_Class) return Parent_Class_Ptr;
> end Parent_Package;
>
> ------------------------
> -- parent_package.adb --
> ------------------------
> with Parent_Package.Child_Package;
> package body Parent_Package is
>    function Construct (Sender : in Parent_Class) return Parent_Class_Ptr is
>       New_Parent : constant Parent_Class_Ptr := new Parent_Class;
>    begin
>       New_Parent.Child := Sender.Child.Construct;
>       New_Parent.Modes := Sender.Modes.Construct;
>       return New_Parent;
>    end Construct;
> end Parent_Package;
>
> --------------------------------------
> -- parent_package-child_package.ads --
> --------------------------------------
> package Parent_Package.Child_Package is
>    type Parent_Queue_Class is tagged
>       record
>          Next   : access Parent_Queue_Class;
>          Parent : access Parent_Class;
>       end record;
>    type Parent_Queue_Class_Ptr is access all Parent_Queue_Class;
>    function Construct (Sender : in Parent_Queue_Class) return Parent_Queue_Class_Ptr;
>
>    type Modes_Queue_Class is tagged
>       record
>          Next : access Modes_Queue_Class;
>          Mode : Integer;
>       end record;
>    type Modes_Queue_Class_Ptr is access Modes_Queue_Class;
>    function Construct (Sender : in Modes_Queue_Class) return Modes_Queue_Class_Ptr;
> end Parent_Package.Child_Package;
>
> --------------------------------------
> -- parent_package-child_package.ads --
> --------------------------------------
> package body Parent_Package.Child_Package is
>    function Construct
>      (Sender : in Parent_Queue_Class) return Parent_Queue_Class_Ptr is
>       pragma Unreferenced (Sender);
>       New_Queue : constant Parent_Queue_Class_Ptr := new Parent_Queue_Class;
>    begin
>       return New_Queue;
>    end Construct;
>
>    function Construct
>      (Sender : in Modes_Queue_Class) return Modes_Queue_Class_Ptr is
>       pragma Unreferenced (Sender);
>       New_Queue : constant Modes_Queue_Class_Ptr := new Modes_Queue_Class;
>    begin
>       New_Queue.Mode := 0;
>       return New_Queue;
>    end Construct;
> end Parent_Package.Child_Package;
>
> ---------------------
> -- parent_main.adb --
> ---------------------
> with Parent_Package;
> procedure Parent_Main is
>    Obj : Parent_Package.Parent_Class_Ptr;
> begin
>    Obj := Obj.Construct;
> end Parent_Main;
>
> ---------------------------
> when I build the code, I get the messages:
>         warning: useless assignment to "Obj", value never referenced (ok, I agree sure)
>         warning: null value not allowed here
>         warning: "Constraint_Error" will be raised at run time
>
> and sure when I execute the code I get
>         raised CONSTRAINT_ERROR : parent_main.adb:5 access check failed
>
>         (BTW, if I implement the constructors independent from the class - i.e. without referencing the parent class as the argument -, they return no error message and the results after that are according to expected, but sure it breaks the oo design.)
>
> So, how can I fix this?
> Thanks!

Easiest way?
Probably to change "function Construct (Sender : in Parent_Class)
return Parent_Class_Ptr" to something like:
"procedure (Item : out Parent_Class_Ptr)"



      parent reply	other threads:[~2011-10-07  0:10 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
2011-11-09  9:00             ` Simon Wright
2011-11-10  3:54               ` Rego, P.
2011-10-07  0:08 ` Shark8 [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