scoping question

2

2b|!2b==?

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<ModelType> ModelTypes ;

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

Ivan Vecerina

: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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top