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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.176.27.97 with SMTP id n33mr92773uai.10.1498483492852; Mon, 26 Jun 2017 06:24:52 -0700 (PDT) X-Received: by 10.157.46.21 with SMTP id q21mr3083otb.11.1498483492700; Mon, 26 Jun 2017 06:24:52 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!m54no853126qtb.1!news-out.google.com!s132ni2507itb.0!nntp.google.com!f20no1410783itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 26 Jun 2017 06:24:52 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=165.225.16.200; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S NNTP-Posting-Host: 165.225.16.200 References: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <1498048151.20885.28.camel@obry.net> <96174ea5-852d-44e9-8535-7c1eb24d5326@googlegroups.com> <8d3aff06-82df-485f-89e5-a50c326aab05@googlegroups.com> <66aa262e-2ac9-4016-b32d-e9fee14779e1@googlegroups.com> <88e2f18a-0786-4303-a5b8-fe82e8c81dcb@googlegroups.com> <4ad48635-aa1e-45bf-8693-1f77d5fee490@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0abaddd0-e64c-4f5b-9f36-e92f75c863ae@googlegroups.com> Subject: Re: Ada Annoyances From: Maciej Sobczak Injection-Date: Mon, 26 Jun 2017 13:24:52 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:47125 Date: 2017-06-26T06:24:52-07:00 List-Id: > The example must demonstrate dispatch to the operation of the object's=20 > type (the ultimate type) from a body defined for the parent type T class. More complete demonstration: #include class Base { public: Base(); =20 virtual void vfoo(); }; class Derived : public Base { public: Derived(); =20 virtual void vfoo(); }; void useObject(Base & b) { b.vfoo(); } Base::Base() { std::puts(" calling useObject from Base constructor:"); =20 useObject(*this); } void Base::vfoo() { std::puts(" Hello from Base object!"); } Derived::Derived() { std::puts(" calling useObject from Derived constructor:"); =20 useObject(*this); } void Derived::vfoo() { std::puts(" Hello from Derived object!"); } int main() { std::puts("test with Base object:"); Base b; =20 std::puts(""); =20 std::puts("test with Derived object:"); Derived d; } $ g++ test.cpp $ ./a.exe test with Base object: calling useObject from Base constructor: Hello from Base object! test with Derived object: calling useObject from Base constructor: Hello from Base object! calling useObject from Derived constructor: Hello from Derived object! Since the Derived object is constructed in a two-step process, the useObjec= t function is called twice, once from the Base part and once from the Deriv= ed part. The dispatch from the first call does not reach the not-yet-create= d parts of the object, which is a safe behavior. > > C++ has stronger type safety than Ada in this particular context. >=20 > It is apples and oranges. If you choose so. In this particular context, apples taste better. > As I explained C++ has type-specific=20 > constructors while Ada's Initialization is a class-wide constructor. You= =20 > cannot compare them. I can and I should, since both are used to achieve the same design-level in= tent, which is construction of a newly created object. --=20 Maciej Sobczak * http://www.inspirel.com