Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Class in function scope

Reply
Thread Tools

Class in function scope

 
 
zerofighter
Guest
Posts: n/a
 
      05-08-2005
Today I found I can define a class in a function scope, I use vc7.1. I
remember it will generat a error when compile time in vc6.0. Is it a new
feature in vc7.1? Is it a feature of standard C++? Can I compile the code in
GCC?


 
Reply With Quote
 
 
 
 
Ivan Vecerina
Guest
Posts: n/a
 
      05-08-2005
"zerofighter" <(E-Mail Removed)> wrote in message
news:d5kc03$di4$(E-Mail Removed)...
> Today I found I can define a class in a function scope, I use vc7.1. I
> remember it will generat a error when compile time in vc6.0. Is it a new
> feature in vc7.1? Is it a feature of standard C++? Can I compile the code
> in GCC?

It is a feature of standard C++ (actually inherited from C, where it was
present). It will work in GCC as well, I even think it would work in VC6.

However, such a class definition currently has limitations. In particular,
it cannot be used to instantiate a template. This makes it impossible to
use such a 'local class' to locally implement the predicate of an STL
algorithm. I would expect that this limitation will be removed in the
next C++ standard.

hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble understanding function scope and variable scope Andrew Falanga Javascript 2 11-22-2008 09:23 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Scope - do I need two identical classes, each with different scope? ann Java 13 09-13-2005 03:07 AM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM



Advertisments