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,9fd97969641aa8c6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsgate.cistron.nl!skynet.be!newspost001!tjb!not-for-mail Date: Mon, 06 Dec 2004 12:49:31 +0100 From: Adrien Plisson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: fr-fr, fr-be, fr, en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: how can i allocate an objekt with initialization??? References: <3459883.9H2ke8dEzz@linux1.krischik.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <41b44663$0$9298$ba620e4c@news.skynet.be> Organization: -= Belgacom Usenet Service =- NNTP-Posting-Host: dc47737d.news.skynet.be X-Trace: 1102333539 news.skynet.be 9298 217.136.144.9:3757 X-Complaints-To: usenet-abuse@skynet.be Xref: g2news1.google.com comp.lang.ada:6796 Date: 2004-12-06T12:49:31+01:00 List-Id: Ole-Hjalmar Kristensen wrote: > You are confused. You can use inheritance and virtual functions in C++ > as well without using pointers: you are confused too... see below. > int main(int argc, char *argv[]) > { > b my_b(1); > c my_c(2); > > test(my_b); > test(my_c); > > return 0; > } your complete example is valid (though a little bit off-topic), but the OP was trying to declare a variable which can hold any object from the class hierarchy FATHER_CLASS and initialize it with a CHILD_CLASS object. the corresponding C++ example should have been: int main(int argc, char *argv[]) { a &my_object = b(1); my_object.f(); return 0; } note: Martin Krischik was noting that in Ada we can avoid pointers/references to do this, unlike in C++. our 2 examples just confirm that (plus it does not help much...). -- rien