From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5f0f4bfb0467bb19 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.21.229 with SMTP id y5mr7126635pbe.1.1317946210780; Thu, 06 Oct 2011 17:10:10 -0700 (PDT) Path: lh7ni13124pbb.0!nntp.google.com!news1.google.com!postnews.google.com!q24g2000vby.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Constructors with multiple inheritance Date: Thu, 6 Oct 2011 17:08:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <11513972.2788.1317325228383.JavaMail.geo-discussion-forums@yqnv12> NNTP-Posting-Host: 24.230.151.194 Mime-Version: 1.0 X-Trace: posting.google.com 1317946210 1306 127.0.0.1 (7 Oct 2011 00:10:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 7 Oct 2011 00:10:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q24g2000vby.googlegroups.com; posting-host=24.230.151.194; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,gzip(gfe) Xref: news1.google.com comp.lang.ada:18332 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-10-06T17:08:23-07:00 List-Id: On Sep 29, 2:40=A0pm, "Rego, P." wrote: > Hi people > > I have a package which implements a class with two items which actually a= re classes which builds different kind of queues. One of them is a queue wh= ose items are of the kind of the parent class. I need to implement a constr= uctor to the parent class, then I need to implement the constructors for th= e two queues. For me, it`s more intuitive from OO point of view that the th= ree constructors are implemented as methods (not just independent calls), a= nd 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 > =A0 =A0type Parent_Class is tagged > =A0 =A0 =A0 record > =A0 =A0 =A0 =A0 =A0Child : access Child_Package.Parent_Queue_Class; > =A0 =A0 =A0 =A0 =A0Modes : access Child_Package.Modes_Queue_Class; > =A0 =A0 =A0 end record; > =A0 =A0type Parent_Class_Ptr is access all Parent_Class; > =A0 =A0function 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 > =A0 =A0function Construct (Sender : in Parent_Class) return Parent_Class_= Ptr is > =A0 =A0 =A0 New_Parent : constant Parent_Class_Ptr :=3D new Parent_Class; > =A0 =A0begin > =A0 =A0 =A0 New_Parent.Child :=3D Sender.Child.Construct; > =A0 =A0 =A0 New_Parent.Modes :=3D Sender.Modes.Construct; > =A0 =A0 =A0 return New_Parent; > =A0 =A0end Construct; > end Parent_Package; > > -------------------------------------- > -- parent_package-child_package.ads -- > -------------------------------------- > package Parent_Package.Child_Package is > =A0 =A0type Parent_Queue_Class is tagged > =A0 =A0 =A0 record > =A0 =A0 =A0 =A0 =A0Next =A0 : access Parent_Queue_Class; > =A0 =A0 =A0 =A0 =A0Parent : access Parent_Class; > =A0 =A0 =A0 end record; > =A0 =A0type Parent_Queue_Class_Ptr is access all Parent_Queue_Class; > =A0 =A0function Construct (Sender : in Parent_Queue_Class) return Parent_= Queue_Class_Ptr; > > =A0 =A0type Modes_Queue_Class is tagged > =A0 =A0 =A0 record > =A0 =A0 =A0 =A0 =A0Next : access Modes_Queue_Class; > =A0 =A0 =A0 =A0 =A0Mode : Integer; > =A0 =A0 =A0 end record; > =A0 =A0type Modes_Queue_Class_Ptr is access Modes_Queue_Class; > =A0 =A0function Construct (Sender : in Modes_Queue_Class) return Modes_Qu= eue_Class_Ptr; > end Parent_Package.Child_Package; > > -------------------------------------- > -- parent_package-child_package.ads -- > -------------------------------------- > package body Parent_Package.Child_Package is > =A0 =A0function Construct > =A0 =A0 =A0(Sender : in Parent_Queue_Class) return Parent_Queue_Class_Ptr= is > =A0 =A0 =A0 pragma Unreferenced (Sender); > =A0 =A0 =A0 New_Queue : constant Parent_Queue_Class_Ptr :=3D new Parent_Q= ueue_Class; > =A0 =A0begin > =A0 =A0 =A0 return New_Queue; > =A0 =A0end Construct; > > =A0 =A0function Construct > =A0 =A0 =A0(Sender : in Modes_Queue_Class) return Modes_Queue_Class_Ptr i= s > =A0 =A0 =A0 pragma Unreferenced (Sender); > =A0 =A0 =A0 New_Queue : constant Modes_Queue_Class_Ptr :=3D new Modes_Que= ue_Class; > =A0 =A0begin > =A0 =A0 =A0 New_Queue.Mode :=3D 0; > =A0 =A0 =A0 return New_Queue; > =A0 =A0end Construct; > end Parent_Package.Child_Package; > > --------------------- > -- parent_main.adb -- > --------------------- > with Parent_Package; > procedure Parent_Main is > =A0 =A0Obj : Parent_Package.Parent_Class_Ptr; > begin > =A0 =A0Obj :=3D Obj.Construct; > end Parent_Main; > > --------------------------- > when I build the code, I get the messages: > =A0 =A0 =A0 =A0 warning: useless assignment to "Obj", value never referen= ced (ok, I agree sure) > =A0 =A0 =A0 =A0 warning: null value not allowed here > =A0 =A0 =A0 =A0 warning: "Constraint_Error" will be raised at run time > > and sure when I execute the code I get > =A0 =A0 =A0 =A0 raised CONSTRAINT_ERROR : parent_main.adb:5 access check = failed > > =A0 =A0 =A0 =A0 (BTW, if I implement the constructors independent from th= e class - i.e. without referencing the parent class as the argument -, they= return no error message and the results after that are according to expect= ed, 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)"