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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA 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-7-bit Received: by 10.68.0.170 with SMTP id 10mr5209099pbf.2.1320915702237; Thu, 10 Nov 2011 01:01:42 -0800 (PST) Path: h5ni21312pba.0!nntp.google.com!news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 10 Nov 2011 10:01:12 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Constructors with multiple inheritance References: <11513972.2788.1317325228383.JavaMail.geo-discussion-forums@yqnv12> <1rj1mmkvwud1d.dzqoy4jhdfca$.dlg@40tude.net> <4976045.4489.1317352313370.JavaMail.geo-discussion-forums@yqjw35> <2pu3h5hqltxi$.ze4yrf1f2y8z.dlg@40tude.net> <23774546.1654.1317391464047.JavaMail.geo-discussion-forums@yqnk41> <1gnrks1djlaok.1k0r5f8z9ylfx.dlg@40tude.net> <21605158.153.1320805494018.JavaMail.geo-discussion-forums@yqiu15> <6366850.176.1320896821400.JavaMail.geo-discussion-forums@yqcm23> In-Reply-To: <6366850.176.1320896821400.JavaMail.geo-discussion-forums@yqcm23> Message-ID: <4ebb92d9$0$6640$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 10 Nov 2011 10:01:14 CET NNTP-Posting-Host: 94f52523.newsspool2.arcor-online.net X-Trace: DXC=WRLEYm\AN5^YI9]OHn9o5^A9EHlD;3YcR4Fo<]lROoRQ8kFejVX[N23ZIDa;Q_=T0Gj=SfJXQ X-Complaints-To: usenet-abuse@arcor.de Xref: news2.google.com comp.lang.ada:14391 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-11-10T10:01:14+01:00 List-Id: 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.