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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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.30.34 with SMTP id p2mr5133747pbh.4.1320914031500; Thu, 10 Nov 2011 00:33:51 -0800 (PST) Path: h5ni21178pba.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Constructors with multiple inheritance Date: Thu, 10 Nov 2011 08:33:51 +0000 Organization: A noiseless patient Spider Message-ID: 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> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="22905"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dRI3sFIG7cA8Bt8xwUFVVC1yhVmSL4sw=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:LfPlLREby2U4mOH0p72G0SWuAEw= sha1:wux9HMLLJOe5njb2BZ4aTbjCm3E= Xref: news2.google.com comp.lang.ada:14389 Content-Type: text/plain; charset=us-ascii Date: 2011-11-10T08:33:51+00:00 List-Id: "Rego, P." writes: > Maybe I can explain this easier trying to use C++. Let's suppose I > have a class Par_Class with an integer and a pointer to a string. I > could code, for example, (please correct me if I'm doing wrong) > > class Par_Class { > public: > Par_Class (int aValue, const char *aName); > > private: > int theValue; > char *theName; > }; > > the constructor could be implemented as > > Par_Class::Par_Class (int aValue, const char *aName){ > theValue = aValue; > strcpy (theName, aName); > }; > > and finally we could instantiate this class with > > Par_Class Par_Obj (23, "My object is this"); > > and sure this constructor method belongs to the class Par_Class and > not to any other class. Par_Class (int aValue, const char *aName) is the very special C++ constructor syntax; when used the compiler generates a new blank area of memory and the constructor gets to fill it in. This is *not* the same as function Construct (P : access Par_Class; aValue : Integer; aName : Integer_Ptr) return Par_Class_Ptr; which requires there to be a previous Par_Class instance; the nearest (Ada 2012) equivalent is I think function Construct (aValue : Integer; aName : Integer_Ptr) return Par_Class is begin return Result : Par_Class do Result.theValue := aValue; Result.theName := aName; end return; end Construct; or, OK for Ada 95 and nearest to your present scheme: function Construct (aValue : Integer; aName : Integer_Ptr) return Par_Class_Ptr is P_Ptr : constant Par_Class_Ptr := new Par_Class; begin P_Ptr.theValue := aValue; P_Ptr.theName := aName; return P_Ptr; end Construct;