Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old April 21st, 2007, 03:45 AM
2b|!2b==?
Guest
 
Posts: n/a
Default scoping question

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
Default 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

 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles