Class in function scope

Z

zerofighter

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?
 
I

Ivan Vecerina

zerofighter said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top