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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f2ce8bda9cae4ab X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!news.tu-darmstadt.de!news.belwue.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: "Must instantiate controlled types at library level." Why? Date: Wed, 12 May 2004 13:55:08 +0200 Organization: AdaCL Message-ID: <13392802.3gDeTK7ybb@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1084364909 01 16513 c062GLWvzSzgAmc 040512 12:28:29 X-Complaints-To: usenet-abuse@t-online.de X-ID: Tnry3QZUQeboFRSTxsO4KtDExvcGjKUztdUSQP630oMs1xMYr8bOw1 User-Agent: KNode/0.7.7 Xref: controlnews3.google.com comp.lang.ada:482 Date: 2004-05-12T13:55:08+02:00 List-Id: Peter C. Chapin wrote: > Jeffrey Carter wrote in news:NJeoc.16758$V97.5496 > @newsread1.news.pas.earthlink.net: > >> The call to Library_Level.Op would attempt to dispatch to >> Outer.Inner.Op, which is out of scope. The references to I in >> Outer.Inner.Op refer to a variable that no longer exists. > > Thank you for your detailed post. It was very helpful. I haven't yet > gotten around to studying Ada's object oriented features in detail but I > can see that the issue is related to the fact that Ada allows procedures > to be defined inside other procedures. > > Just for fun I attached an equivalent C++ program below. Interestingly, it > seems to compile and work using three different C++ compilers. I wonder > its behavior is technically "undefined". It seems like it probably should > be. Perhaps I'll ask on the C++ group. It is not quite complete: > -----> cut <----- > #include > > class X { > public: > virtual void f(); > }; > > void X::f() > { > std::cout << "I'm in X::f\n"; > } > > X *ptr; > > void helper() > { auto int Z := 5; > class Y : public X { > public: > virtual void f() { > std::cout << "I'm in Y::f\n"; std::cout << "and Z is " << Z << std:endl; > } > }; > > ptr = new Y; > } > > int main() > { > helper(); > ptr->f(); > return 0; > } But you can reduce the probem to a 5 liner: int& Very_Silly () { auto int Short_Lived = 5; return Short_Lived; } A good compiler will warn you. But it does compile. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com