473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 ?

Apr 21 '07 #1
1 1131
"2b|!2b==?" <ro**@your.box.comwrote in message
news:DK******************************@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

Apr 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Stockwell | last post by:
Hi, Another of my crazy questions. I'm just in the process of learning so bear with me if you can. I actually ran it.... with two test cases TEST CASE 1: Say I have the following defined:...
8
by: It's me | last post by:
This must be another newbie gotchas. Consider the following silly code, let say I have the following in file1.py: #============= import file2 global myBaseClass myBaseClass =...
4
by: Frederick Grim | last post by:
okay so the code in question looks like: namespace util { template<typename C> inline void mmapw(C *& ptr, size_t length, int prot, int flags, int fd, off_t offset) { if((ptr =...
4
by: Joel Gordon | last post by:
Hi, When I try and compile the a class containing the following method : public void doSomething() { for (int i=0; i<5; i++) { IList list = new ArrayList(); Console.WriteLine( i /...
4
by: Sohum | last post by:
Hi I'm reasonably new to this group, and to programming in general. I'd like to know, can you selectively scope within an interface? For example: Public Interface MyInterface Friend...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
3
by: morris.slutsky | last post by:
So every now and then I like to mess around with hobby projects - I often end up trying to write an OpenGL video game. My last attempt aborted due to the difficulty of automating game elements and...
17
by: Chad | last post by:
The following question stems from Static vs Dynamic scoping article in wikipedia. http://en.wikipedia.org/wiki/Scope_(programming)#Static_versus_dynamic_scoping Using this sites example, if I...
3
by: SPECTACULAR | last post by:
Hi all. I have a question here.. what kind of scoping does C++ use? and what kind does Smalltalk use? I know smalltalk is a little bit old .. but any help would be appreciated.
1
by: jholg | last post by:
Hi, regarding automatically adding functionality to a class (basically taken from the cookbook recipee) and Python's lexical nested scoping I have a question wrt this code: #-----------------...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.