Connecting Tech Pros Worldwide Help | Site Map

scoping question

  #1  
Old April 21st, 2007, 03:45 AM
2b|!2b==?
Guest
 
Posts: n/a
I am getting strange compiler behaviour (compiler crashes) when building
some code. here is a snippet ..:


I have the ff class and type defs:


class A
{
public:

struct Type
{
enum Enum
{
FirstItem = -1 ,
Barney1 ,
Barney2 ,
Barney3 ,
LastItem
};
};
typedef Type::Enum ModelType ;
typedef std::vector<ModelTypeModelTypes ;

struct Result
{
enum Enum
{
FirstItem = 0,
Fred1 ,
Fred2 ,
LastItem
};
};
typedef Result::Enum ResultType ;

.....

};



The line that causes the compielr to crash looks like this:

int temp = somefunc();
if ( temp <= A::ResultType::FirstItem || temp >=
A::ResultType::LastItem )
{
.... //do domething
}

Is there something patently wrong about this. I know I am being cheeky
using the 'tags' First/LastItem in the enumerations, but I thought they
had different scopes ?

  #2  
Old April 21st, 2007, 04:15 AM
Ivan Vecerina
Guest
 
Posts: n/a

re: scoping question


"2b|!2b==?" <root@your.box.comwrote in message
news:DKidnZAosIo_5bTbnZ2dnUVZ8qCqnZ2d@bt.com...
:I am getting strange compiler behaviour (compiler crashes) when
building
: some code. here is a snippet ..:
....
: struct Result
: {
: enum Enum
: {
: FirstItem = 0,
: Fred1 ,
: Fred2 ,
: LastItem
: };
: };
: typedef Result::Enum ResultType ;
....
: The line that causes the compielr to crash looks like this:
:
: int temp = somefunc();
: if ( temp <= A::ResultType::FirstItem || temp >=
: A::ResultType::LastItem )
....
: Is there something patently wrong about this.

In the current C++ standard specification, enum definitions
do not create a scope:
Result::Enum::FirstItem // does not exist in C++98
Result::FirstItem // here it is...
So the following would work:
if( temp<=Result::FirstItem || temp>=Result::LastItem )

Note that Result::Enum::FirstItem is expected to become
valid in the next revision of the C++ standard, and might
be implemented as an extension by some compilers today.


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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scoping rules Chad answers 17 October 11th, 2006 05:05 PM
A scoping question It's me answers 8 July 18th, 2005 08:35 PM
Beginner's scoping question Alan Little answers 6 July 18th, 2005 06:35 PM