Anther inner class question

Discussion in 'C++' started by Glen Able, Feb 10, 2004.

  1. Glen Able

    Glen Able Guest

    class Outer
    {
    typedef int MyInt;

    class Inner
    {
    Outer::MyInt m_thing;
    };
    };

    In this case, when VC sees the declaration of m_thing, it gives the error
    "use of undefined type 'Outer'"

    Shouldn't this compile OK? I'm assuming there's no special scoping rules
    for typedefs are there?

    thanks.
     
    Glen Able, Feb 10, 2004
    #1
    1. Advertising

  2. Glen Able

    Sharad Kala Guest

    "Glen Able" <> wrote in message
    news:c0aooh$cka$1$...
    > class Outer
    > {
    > typedef int MyInt;
    >
    > class Inner
    > {
    > Outer::MyInt m_thing;
    > };
    > };
    >


    Which VC?
    VC 7 doesn't complain about this code, same with Comeau online.
     
    Sharad Kala, Feb 10, 2004
    #2
    1. Advertising

  3. Glen Able

    Glen Able Guest

    > "Glen Able" <> wrote in message
    > news:c0aooh$cka$1$...
    > > class Outer
    > > {
    > > typedef int MyInt;
    > >
    > > class Inner
    > > {
    > > Outer::MyInt m_thing;
    > > };
    > > };
    > >

    >
    > Which VC?
    > VC 7 doesn't complain about this code, same with Comeau online.
    >

    Sorry, that's VC6. So, I guess that code *is* valid, then. Seems like
    there are quite a few scope-related bugs in VC6, no?
     
    Glen Able, Feb 10, 2004
    #3
  4. "Glen Able" <> writes:

    > > "Glen Able" <> wrote in message
    > > news:c0aooh$cka$1$...
    > > > class Outer
    > > > {
    > > > typedef int MyInt;
    > > >
    > > > class Inner
    > > > {
    > > > Outer::MyInt m_thing;
    > > > };
    > > > };
    > > >

    > >
    > > Which VC?
    > > VC 7 doesn't complain about this code, same with Comeau online.
    > >

    > Sorry, that's VC6. So, I guess that code *is* valid, then. Seems like
    > there are quite a few scope-related bugs in VC6, no?


    Actually, it's not a scope-related bug, but an accessibility problem.
    According to the standard, inner classes don't have access to private
    members of the outer class (this is considered a defect in the standard,
    though - see http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45)
    As a workaround, you can either make the typedef public or make Inner a
    friend of Outer.

    HTH & kind regards
    frank

    --
    Frank Schmitt
    quattro research GmbH
    e-mail: schmitt NO at SPAM quattro-research !@! dot com
     
    Frank Schmitt, Feb 11, 2004
    #4
    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. kishan bisht
    Replies:
    2
    Views:
    2,945
    xarax
    Jul 2, 2003
  2. Tor Iver Wilhelmsen
    Replies:
    0
    Views:
    430
    Tor Iver Wilhelmsen
    Jul 18, 2003
  3. E11
    Replies:
    1
    Views:
    4,902
    Thomas Weidenfeller
    Oct 12, 2005
  4. Carlo v. Dango
    Replies:
    14
    Views:
    1,088
    Alex Martelli
    Oct 19, 2003
  5. Pyenos
    Replies:
    2
    Views:
    407
    Pyenos
    Dec 27, 2006
Loading...

Share This Page