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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f2ce8bda9cae4ab X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!news-xfer.newsread.com!newsread.com!newsstand.newsread.com!POSTED.monger.newsread.com!not-for-mail Newsgroups: comp.lang.ada Subject: Re: "Must instantiate controlled types at library level." Why? From: "Peter C. Chapin" References: <13392802.3gDeTK7ybb@linux1.krischik.com> Organization: Kelsey Mountain Software Message-ID: User-Agent: Xnews/5.04.25 Date: Thu, 13 May 2004 02:59:02 GMT NNTP-Posting-Host: 216.114.169.63 X-Complaints-To: Abuse Role , We Care X-Trace: monger.newsread.com 1084417142 216.114.169.63 (Wed, 12 May 2004 22:59:02 EDT) NNTP-Posting-Date: Wed, 12 May 2004 22:59:02 EDT Xref: controlnews3.google.com comp.lang.ada:515 Date: 2004-05-13T02:59:02+00:00 List-Id: Martin Krischik wrote in news:13392802.3gDeTK7ybb@linux1.krischik.com: > 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; >> } Actually I tried this modification. In fact, the three C++ compilers I used *do* produce a compile time error on this code. In particular the use of an auto variable in the member function of a local class is specifically illegal. The relevant language from the C++ standard is in section section 9.8, paragraph 1: "Declarations in a local class can use only type names, static variables, extern variables and functions, and enumerators from the enclosing scope." The standard then goes on to give an example showing that the use of an auto variable is illegal. So it appears that contrary to my earlier assumption, C++ does in fact try to do something sensible with this construction. Peter