scoping question

Discussion in 'C++' started by 2b|!2b==?, Apr 21, 2007.

  1. 2b|!2b==?

    2b|!2b==? Guest

    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 ?
    2b|!2b==?, Apr 21, 2007
    #1
    1. Advertising

  2. "2b|!2b==?" <> wrote in message
    news:D...
    :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
    Ivan Vecerina, Apr 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt S.
    Replies:
    0
    Views:
    395
    Matt S.
    May 4, 2004
  2. Alan Little

    Beginner's scoping question

    Alan Little, Nov 10, 2004, in forum: Python
    Replies:
    6
    Views:
    267
    Alan Little
    Nov 12, 2004
  3. It's me

    A scoping question

    It's me, Dec 28, 2004, in forum: Python
    Replies:
    8
    Views:
    334
    Dennis Lee Bieber
    Dec 28, 2004
  4. Matt Barnicle
    Replies:
    10
    Views:
    634
    Bruno Desthuilliers
    Dec 2, 2007
  5. Cornelius Keller

    variable & scoping question.

    Cornelius Keller, Aug 10, 2009, in forum: Python
    Replies:
    8
    Views:
    315
    Steven D'Aprano
    Aug 11, 2009
Loading...

Share This Page