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 Path: g2news1.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!news.mathworks.com!newsfeed.mathworks.com!news-peer0-test!btnet-feed5!btnet!carbon.eu.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: how can i allocate an objekt with initialization??? Date: 06 Dec 2004 11:04:56 +0100 Organization: Sun Microsystems Message-ID: References: <3459883.9H2ke8dEzz@linux1.krischik.com> NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: new-usenet.uk.sun.com 1102327500 27154 129.159.112.195 (6 Dec 2004 10:05:00 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 6 Dec 2004 10:05:00 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:6794 Date: 2004-12-06T10:05:00+00:00 List-Id: >>>>> "MK" == Martin Krischik writes: MK> Thomas Bruns wrote: >> TEST : FATHER_CLASS_PTR; >> >> begin >> TEST:= new CHILD_CLASS'( INT=>1); -- i will initialze the objekt here,but MK> Since you are initializing an element form the parent class you need to MK> initialize the child as well: MK> TEST:= new CHILD_CLASS'( MK> INT1 =>1 MK> INT2 =>1); MK> only the other way round you can shortcut: MK> TEST:= new CHILD_CLASS'( MK> FATHER_CLASS MK> WITH MK> INT2 =>1); MK> And the standart question for beginners: Are you shure you need a pointer? MK> Unlike C/C++/Java Ada allows for: MK> TEST : FATHER_CLASS'Class :=�CHILD_CLASS'( MK> INT1 =>1 MK> INT2 =>1); MK> You can use inheritance in Ada without using pointers! FATHER_CLASS'Class MK> can be used just like a String - you can pass it around as parameter, MK> return it from a function, store it in a record. There are collection MK> libraries where you can store them. You are confused. You can use inheritance and virtual functions in C++ as well without using pointers: #include class a { private: int _value; public: a(int x) : _value(x) {} int n(){return _value;} virtual void f() = 0; }; class b : public a { public: b(int x) : a(x) {} void f(); }; void b::f() { std::cout << "I am b " << n() <<"\n"; } class c : public a { public: c(int x) : a(x) {} void f(); }; void c::f() { std::cout << "I am c " << n() << "\n"; } void test(a& x) { x.f(); } int main(int argc, char *argv[]) { b my_b(1); c my_c(2); test(my_b); test(my_c); return 0; } MK> With Regards MK> Martin MK> -- MK> mailto://krischik@users.sourceforge.net MK> http://www.ada.krischik.com -- C++: The power, elegance and simplicity of a hand grenade.